demolaynyc
Dec 11 2006, 06:38 PM
Okay so I got this sample link (not working): http://www.acosta.com/joo.asp?id=654Now suppose I have a PHP file that would use MySql in order to get all values in the row where id 654 is found. Here's a sample DB: Table: demnyc ______________________________________ | id | Name | Age | Email | *----------------------------------------------------* | 1 | Albert | 17 | no email | *----------------------------------------------------* | 2 | YaPow | 888 | no email | |______________________________________| The result should be "Albert" Here's a portion of the current code to display the desired value: CODE $query = "SELECT Name FROM demnyc WHERE id=1"; $result = mysql_query($query);
print "$result";
The current result is: Resource id # 4Can someone tell me please what I'm missing?
Reply
pyost
Dec 11 2006, 06:50 PM
When you use mysql_query, it doesn't return a string/number, but rather a resource. For example, if you select more rows, how would you display them? That's why mysql_result is used. After selecting a row from the table (or rows), you will get $result. In order to use it, you must do this: CODE $someVariable = mysql_result($result,0); By doing this, $someVariable will be assigned the value from the first row of $result (0 is for the first row, 1 for the second etc). You can also add another parameter after the "0" which will indicate what column you want to use, if more have been selected.
Reply
Hercco
Dec 11 2006, 07:50 PM
Yes indeed, you get the resource from which you can pull the actual data. Mysql_result() is fine function to use if you need to fetch only one row and value from it. However these cases are quite rare and for instance I can't remember ever using the basic function. Instead use mysql_fetch_assoc() or mysql_fetch _row() which fetch one entire row from which you have access to all the values your query returned. The difference between these two is that mysql_fetch_assoc() gives you an associative array, for exmple $result['id'] would point to the id value which with mysql_fetch_row() it'd be $result[0] (presuming 'id' is mentioned first in the query). There's also a third alternative mysql_fetch_object() which doesn't return an array but an object. Nice if you like to work with objects. (duh) Under no circumstance use mysql_result() in a loop to get entire row. I've seen code like that and I nearly had a stroke. 
Reply
demolaynyc
Dec 11 2006, 08:39 PM
Oh so would the syntax be like: $result = mysql_query($query); $name = mysql_fetch_row($result[0]); Would this syntax be right?
Reply
pyost
Dec 11 2006, 09:53 PM
QUOTE(demolaynyc @ Dec 11 2006, 09:39 PM)  $name = mysql_fetch_row($result[0]);
No, because $result is not an array, it is a resource. $name = mysql_fetch_row($result);This, on the other hand, will work. After doing this, you will get $name - and that's an array. But, as Hercco said, you are better off with mysql_fetch_assoc(), because you will be able to use column names instead of numbers. (so that's $name["column"]).
Reply
iGuest
Aug 7 2008, 01:51 PM
How do I retrieve related data using Mysql/php on id query? If this make sense
PHP & MySQL: Displaying Content From A Given ID
I Have set up a video website whereby a user selects a video to play, but I have other videos which I want to display that are related but I am only getting the output for the selected video. I am new to this and the frustration is killing me trying to get this to work. Can someone tell me the best way to approach this. Regds Wilburwt -question by Wilburwt
Reply
iGuest
Aug 7 2008, 01:57 PM
How do I retrieve related data using Mysql/php on id query? If this make sense
PHP & MySQL: Displaying Content From A Given ID
I Have set up a video website whereby a user selects a video to play, but I have other videos which I want to display that are related but I am only getting the output for the selected video. I am new to this and the frustration is killing me trying to get this to work. Can someone tell me the best way to approach this. Regds Wilburwt -question by Wilburwt
Reply
Similar Topics
Keywords : php, and, mysql, displaying, content, id
- What You Need Before You Can Create A Text-based Game..
Using PHP, HTML and MySQL (2)
Mysql Multiple Tables
(1) It is good practice to use multiple tables to sort out big amounts of data. But once you do that it
becomes increasingly hard to cross reference the tables. Mysql has a little beautiful command
structure that they have added. You can select multiple tables within one sql query. Example of a
basic sql query CODE $sql = "SELECT * FROM table WHERE row=1"; If you noticed
that I selected all of the rows in the table. Normally you will try to not select the entire table
from the database unless you absolutely want all of the table. I would recommend against....
Any Website Provide Free Host Mysql Host?
(4) any website provide free host mysql host? i need it because i am using 000webhost.com now but it
only provide 2 mysql database... can i know where or how can i get more databases regards....
How To: Display A Members/user List.
With PHP, Mysql, and HTML. (3) Alright, some of you might want to display your User's or Members on your site. Notes: 1.This
is to fit in with Feelay's register and Log-in scripts you can find in the tutorial section. 2.I
made this to show the members of my site who is a member and what their ID is. First off, we must
set up a connection to our MySQL Database. CODE <?php $con =
mysql_connect("localhost","database_username","database_username_password
4;); if (!$con) { die('Could not connect: ' .
mysql_error(....
Mysql On Computer
XD (9) I posted PHP on computer? , but for some reason it doesn't show :/. Anyways I am wondering if
there is MYSQL on my computer, meaning can i make a data base on my computer? that way i make what i
want and upload it when i get hosted =)....
Can You Link Game Maker With Mysql/php
Title says it :D (0) Hello, I am new to this service and i think I am going to like it =). Anyway, my main question is
can you link executable games made by gamemaker (i have pro) to a database? And can i use the php
server i get here to transfer data to that game? If so i would appreciate a little help with it
because I am new to both =). Also is there anyway to get a www.mywebsite.com via credits from
astahost? Finally is there any group here that works with gamemaker? we might have small contests
or so /tongue.gif" style="vertical-align:middle" emoid=":P" border="0" alt="tongue.gif" /....
Mysql Database Entry By Excel Sheets
(2) Hello .. I would like to ask if i can use use Microsoft excel files in order to make entries to
mysql database. Thanks....
Mysql Database Management
(1) Hi i am new, I have a problem in understanding the query decomposition in D-DB. Can anyone help me
to understand the first question of the exercise 25.21 of Elmasri-Navath 4th edition? Consider the
following relations: BOOKS (Book#, Primary_author, Topic, Total_stock, $price) BOOKSTORE
(Store#, City, State, Zip, Inventory_value) STOCK (Store#, Book#, Qty) Consider a distributed
database for a bookstore chain called National Books with 3 sites called EAST, MIDDLE, and WEST.
Consider that BOOKS are fragmented by $price amounts into: B1:BOOK1:up to $20.....
Mysql And User File_priv
(0) HI, I've hit the grain while trying to import file to mysql database - I need to enable file
permissions of the database user but this seems not possible with most of the hosting providers.
The problem is to set file_priv of the database user to "Y" . This is done in the "user" table of
the maintanance database named "mysql". cPanel doesn't allow this. Via the cPanel you can only
allow privileges on table querries but you cannot grant host file privileges to the database user -
which makes querries like: "LOAD DATA INFILE 'filename' INTO TABLE tablen....
Mysql With My Own Server
few questions (4) Hi, I've only just joined the forum Can you link the mysql database here to your own website?
If so how would I go about it Thanks =D....
Mysql Storage Engine Error 28
(5) Hello, On my website and forum, SDeckNET, the mySQL database is not working. I get the error "mySQL
error: Got error 28 from storage engine mySQL error code: Date: Wednesday 02nd 2008f July 2008
05:33:53 AM" from my forum. From what I know, error 28 means I'm out of disk space, how can this
be? I was never told of a mySQL space limitation and all these cases of downtime are destroying my
site's memberbase. EDIT: It now seems PhpMyAdmin is down too, with the error: "Warning:
session_write_close() : SQLite: session write query failed: database is full in /usr/l....
Php And Mysql Extension Installation
(0) /** * $Author: pgeric $ * $Revision: 8 $ * $Date: 2008-06-30
19:40:52 +0800 (Mon, 30 Jun 2008) $ * $Id: php_mysql_install.txt 8 2008-06-30 11:40:52Z
pgeric $ */ Installing newer version of php and enable mysql connection. (As of this writing
will be targeted at php 5.2.5 and above) Because of a change on newer version of php. Some files
have been moved around within the default folder structure of php package. The result was when try
working with mysql. It surprise you a lot. (The dicussion on this was based-on zip....
Using Blogger To Add Content
Can I get rid of the header? (9) OK, so I'm building my site and want to add a blog element. Not having PHP and MySQL under my
belt yet, I figure I'll use Blogger. Here's what I do: I set up the account on Blogger and
create the blog with my site as the location I erase the blog's template code and copy and
paste my site in its place I copy and paste the essential Blogger tags and everything in between
that makes the blog element work Functionality is great. I can post on blogger, and it updates my
site without having to go into the html for every addition. Layout and look is a nig....
Mysql Persistant Connections?
Are they allowed here? (2) Hello, I am considering starting to contribute to this community and get free hosting from them but
the hosting im looking for needs one of two things... 1) Persistant MySQL Connections from PHP or
2) A extreamly large amount of max_connections_per_hour set. If these are not offered would it be
possible to get one of them with some extra points? Thanks, Rich....
I Have An Error With My Mysql Connection
mysql connection error (7) ok so here's my web page... http://lacrossems.t35.org/ it only lags cause its trying to
connect to the my sql server...i followed this guide
http://forum.ragezone.com/showthread.php?t=387249 and when i edit my config.php to my host and
login info i always get the error cannot connect to the database here is my config.php if you can
help me CODE <?php $host['naam'] =
'CENSORED'; // my host $host['gebruikersnaam'] =
'righto'; // my database username $host['wach....
Recognizing Third-party Content In Firefox
(2) Hi, Has anyone managed to block third-party content using the AdBlock Plus extension for Firefox?
I found an article here: "Recognizing third-party content"
http://adblockplus.org/blog/recognizing-third-party-content where the developer says it's
possible, but I don't understand the practical implementation. Thanks.....
Content Sites And Mini Sites
(1) Content sites usually profit by educating their visitors. For example, a content site focusing on
dog grooming might provide a basic tutorial to assist their visitors in learning how to groom a dog.
They provide this tutorial completely free; however, the main purpose for this tutorial is to
educate their visitors and promote their products. When you provide your visitors with quality
information that teaches and informs, you are not only gaining their trust in you by sharing your
expertise, but you're also building your credibility, which is very important on the ....
Mysql - So Hard
Come in here if you think MySQL is soo hard! (14) Doesn't anybody think MySQL is so hard to code? I mean think about it, you need loads of
databases just for one little script and you have to type things in like ;Host-Username:
(blahblah) ;Host-Password: (blahblah) ;Host-DatabaseName: (blahblah) Ok, that MySQL code was
random, and it is alot harder than that. If you have expierenced it being hard, you are free to
post right in here, mate.....
Login System Using A Mysql Db
How do i do this? (5) Hi guys, ive got a registration system that looks something like the one below: Firstname:
Lastname: Then i have inset.php, which looks like the following: $con =
mysql_connect("localhost","autobot","abc123"); if (!$con) { die('Could not connect:
' . mysql_error()); }mysql_select_db("my_db", $con);$sql="INSERT INTO person
(username, password) VALUES ('$_POST ','$_POST ')";if
(!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record
added";mysql_close....
Qupis : Free Cpanel Web Hosting (one Line Text Ad At Bottom)
150 MB space, 10000 MB Bandwidth, php, mysql, CPanel (9) Hello Members, We are proud to introduce a new member to Xisto group of sites.
Qupis : Free Web Hosting 150 MB space, 5000 MB Bandwidth, php,
mysql, CPanel (Latest). Emails, FTP, Addon domains, Parked Domains etc.
http://www.Qupis.com
Feel free to add your reviews and comments about it. -AstaHost
Management ....
Navcat For MySQL
is Navcat any good? (8) Hello all, i ve recently come across NavCat (GUI tool) for MySQL. I have not bought a copy yet, just
played around with the demo. Has any one used it beore, if so please let me know if its worth
buying. I already have PhpMyadmin, Just wanna know if NavCat is better than PhpMyAdmin in usibility
and functionality. Regards....
MySQL, Multiple Tables
(24) Ok, I'm coding a project which is a leap than what I'd normally do. Before, I've always
learned ONE table... put EVERYTHING in one database table. I'm making a profile system so there
needs to be at least two tables: 1 for users, 1 for content. My problem is, how do I link the two
together? I could probably figure this out faster if someone explained and posted sample SQL code
that shows how the two are linked together. Thanks!! F....
CuteNews: PHP-based Blog System - No MySQL
(10) I don't know if you guys have heard about CuteNews, but I think it's an awesome blogging
system. If you don't know where to get it or how to set it up, here is a quick run-down.
Download the zip file (virus free) from http://www.mysharebox.com/dl.php?key=8276639 . 1) Unzip
the file. 2) Make a folder titled "cutenews". 3) Upload the contents of the cutenews folder into the
one you've just created. 4) CHMOD the file index.php to 777. 5) CHMOD the folder "data" to 777.
6) Then CHMOD all the files and folders inside of "data" to 777. 7) Go to http://YO....
MySQL Output Database Question
(18) I am new to MySql and have just created a database after using a script. My problem is not the
script, but what it says about putting it into the output file. I cant figure out the right terms
to put it in, I keep getting errors. I try using; SELECT*FROM 'database name' WHERE
'location' but it isnt working. I'm lost with this stuff, I really am. Can someone
please help me out?....
[PHP + MySQL] Encrypting Data
To protect the password of your DB, for example. (9) Hi! This is my 2nd code of PHP + MySQL. This code is VERY simple: it encript the data in the
MySQL DB. Here we go! ------------------------------------------------------------------------
CODE <?php $password = "abc"; $new_password = md5($password);
echo $new_password; ?> The password "abc" was codfied using md5() This will be:
900150983cd24fb0d6963f7d28e17f72 CODE <?php $normal_pass = "abc";
$encripted_pass = "900150983cd24fb0d6963f7d28e17f72"; if(md5($norm....
Need Help With A PHP - MySQL Registration Script
Wont INSERT into the database (13) hey well can some one helpme make this code work it won't INSERT INTO THE DATABSE CODE
<?php # register1.php # common include file to MySQL include("DB.PHP");
$Username=$_POST['Username'];
$Password=$_POST['Password'];
$Name=$_POST['Name']; $Last=$_POST['Last'];
$Sex=$_POST['Sex']; $Month=$_POST['Month'];
$Day=$_POST['Day']; $Year=$_POST['Year&....
Mirror My MySQL Database To Another Mysql Server
(4) Hi..I want to ask if its possible to automatically mirror my mysql databases into another mysql
server?or create a small php script to do this? The reason is because, we all know that database is
very improtant if we have dynamic website. I have my forum hosted and i want to automatically
mirror this or backup into another mysql server(free). Like in freesql.org. So that im not afraid
that i forgot to backup my database..also i have one central backup database. Thanks for the
help..Im looking forward for this posibility.....
Recover Tables From A MySQL .frm File
(8) I have a couple of .frm files with no corresponding data or index files. Is it possible to recover
the table structure (field names, types, sizes, rows,col, etc) from these files? The table type is
innodb....
MySQL Realtime Replication
how to replicate mysql in realtime (4) i dont know if this might be useful to ppl here, but this is a very good knowledge for serious
siteadmins. while i was digging for mysql backup techniques, i've found that mysql is able to
do realtime replication. the idea is that there are master server and slave server. both are having
the same version of mysql installed. the data flows; Master >copy> Slave ( in realtime!)
you'll never have to manually copy the database file of wasting your time to manually use the
mysqldump command. here are the links; http://dev.mysql.com/doc/mysql/en/Replication_HOW....
MySQL - Trouble With Bulk Insert Statements
(3) I'm trying to insert about 500 rows into mysql, but I keep getting errors. If I copy and paste
too many (about 50) insert statements at a time I get errors sometimes. I sometimes even get errors
but then the row is skipped so I don't know there was an error (I'm using linux and SSH).
What's the best way to get my insert statements to put the data in MySQL? Is there anyway that I
can have it tell me if there where any errors all the statements are executed? Thanks for your
help.....
Looking for php, and, mysql, displaying, content, id
|
|
Searching Video's for php, and, mysql, displaying, content, id
|
advertisement
|
|