...

View Full Version : assigning a variable with a database value



boeing747fp
01-07-2004, 01:00 AM
how do i connect to a mysql database and set a variable to equal a row value in a mysql db?

i tried


<?php
$aa = mysql_connect("localhost", "", "");
$db = mysql_select_db("whmx_store",$aa);
$sql_select = "SELECT * FROM cds top1 ORDER BY dateofentry DESC LIMIT 1";
$result = mysql_query($sql_select) or die ("Queryproblem: " . mysql_error());
while ($row = mysql_fetch_array($result)) {
$asin = $row[8];
}
?>

but when i insert the $asin in something, it just shows up on the page as '$asin'

raf
01-07-2004, 01:16 AM
$aa = mysql_connect("localhost", "", "");
$db = mysql_select_db("whmx_store",$aa);
$sql_select = "SELECT columnname FROM cds ORDER BY dateofentry DESC LIMIT 1";
$result = mysql_query($sql_select) or die ("Queryproblem: " . mysql_error());
if (mysql_num_rows($result)== 0){
$echo ('<strong>No rows found.</strong>') ;
} else {
$row = mysql_fetch_assoc($result) ;
mysql_free_result($result);
$asin = $row['columnname'];
}


Loose the top1 --> it's the buggy JetSQL version of Limit1 etcetc
http://www.codingforums.com/showthread.php?s=&threadid=30568&perpage=15&highlight=buggy&pagenumber=1

I suppose you are after the last inserted record? --> Check the sticky on top of the mySQL forum.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum