Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MySQL help 3

Status
Not open for further replies.

PhoenixDown

Programmer
Jul 2, 2001
279
CA
Hi.

How do I get records from rows in a MySQL table into a scalar variable? I want to use them on my web site.
 
Use mysql_fetch_array() to put the data into an arry, then use join() to join the array elements into a single scalar.

But it is not necessary to use join if your output is going to a web browser.
 
Sorry, but can you provide an example? I'm still new to PHP. :-(
 
What is a scalar variable?

For data retrieval, I like to use the MYSQL_ASSOC option for
Code:
mysql_fetch_array
. It makes an associative array so you can refernce the value by using the column name.
Example:
Code:
$query = "SELECT * FROM table_name WHERE id='".$record_id."'";
$result = mysql_query ($query, $linkid);
$rowarray = mysql_fetch_array($result, MYSQL_ASSOC);
$record_data1 = $rowarray["data1"];
Documentation:
 
<?php


$db = mysql_connect(&quot;localhost&quot;, &quot;username&quot;, &quot;password&quot;) or die ('cannot connect to mysql server');

mysql_select_db(&quot;test&quot;,$db) or die ('Cannot select database');

$result = mysql_query(&quot;select * from table_name where stuff&quot;,$db);

$num_rows = mysql_num_rows($result);

echo &quot;<div align=center> Your search has found <b>$num_rows </b>rows \n&quot;;

printf(&quot;%s %s %s %s %s %s \n&quot;, $myrow[0], $myrow[1], $myrow[2], $myrow[3], $myrow[4], $myrow[5]);

}
?>
***************************************
Party on, dudes!
[cannon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top