Strange behaviour from script, please assist

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
guymclaren
Forum Newbie
Posts: 11
Joined: Tue Feb 17, 2009 10:53 pm

Strange behaviour from script, please assist

Post by guymclaren »

I get the following result from the code

5 5 'n faktuur is aan 5 gestuur met volle bank besonderhede

I expected a name, surname and email address rather than the id.

Code: Select all

 
mysql_connect($server,$username,$password);
@mysql_select_db($database) or die("Unable to select database");
 
$sqlq="SELECT * FROM Members WHERE id = '".$ident."'";
$objRS = mysql_query($sqlq);
 
$email = mysql_result($objRS,"email");
$name = mysql_result($objRS,"Name");
$sname = mysql_result($objRS,"Surname");
$add1 = mysql_result($objRS,"Address1");
$add2 = mysql_result($objRS,"Address2");
$city = mysql_result($objRS,"City");
$reference = mysql_result($objRS,"id");
?>
<div id="content">
<div id="contentleft">
<? echo $name." ".$sname." 'n faktuur is aan ".$email." gestuur met volle bank besonderhede"; ?>
<br /><br />
 
 
wpsd2006
Forum Commoner
Posts: 66
Joined: Wed Jan 07, 2009 12:43 am

Re: Strange behaviour from script, please assist

Post by wpsd2006 »

read the php mysql_result tutorial you are missing something there
the second attribute for mysql_result is the row number the third is the cell name

if you have multiple result i suggest using mysql_fetch_assoc or mysql_fetch_row
guymclaren
Forum Newbie
Posts: 11
Joined: Tue Feb 17, 2009 10:53 pm

Re: Strange behaviour from script, please assist

Post by guymclaren »

Code: Select all

# $sqlq="SELECT * FROM Members WHERE id = '".$ident."'";
# $objRS = mysql_query($sqlq);
#  
# $email = mysql_result($objRS, 0,"email");
# $name = mysql_result($objRS, 0,"Name");
# $sname = mysql_result($objRS, 0,"Surname");
 
To help other noobs here is the solution, this is for a single row result. No thanks to someone who suggested I read a pretty useless document. I specifically stated only one result would appear.

I would suggest that if you don't know the answers don't suggest RTFM as an answer. I would not have asked if the solution had been that obvious.
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: Strange behaviour from script, please assist

Post by papa »

Read about the functions that he suggested and you'll probably understand why.
Post Reply