Page 1 of 1

Strange behaviour from script, please assist

Posted: Tue Feb 17, 2009 11:02 pm
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 />
 
 

Re: Strange behaviour from script, please assist

Posted: Wed Feb 18, 2009 3:19 am
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

Re: Strange behaviour from script, please assist

Posted: Wed Feb 18, 2009 4:52 am
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.

Re: Strange behaviour from script, please assist

Posted: Wed Feb 18, 2009 5:36 am
by papa
Read about the functions that he suggested and you'll probably understand why.