PDA

View Full Version : php mysql Resource id #2


ryan
06-17-2005, 12:55 AM
mysql_select_db($dbname, $link);

$query = 'SELECT * FROM `Client Info` LIMIT 0, 30';
$result = mysql_query($query,$link);
if (!$result) {
die('Invalid query: ' . mysql_error());
mysql_close($link);
}
echo $result;


why do i get

Resource id #2

tmilewski
06-20-2005, 06:26 AM
Because that is the Resource ID of your query. What you need to do is this:

<?php

mysql_select_db($dbname, $link);

$query = "SELECT * FROM 'Client Info' LIMIT 0, 30";
$result = mysql_query( $query );

if ( !$result ) // Check if query worked
{
mysql_close( $link );
die( "Invalid query: " . mysql_error() );
}

while( $row = mysql_fetch_array( $result ) ) // Fetch and loop through results
{
echo( $row['COLUMN_NAME'] );
}

?>


1) Close your DB connection before you end the script with the die() function if the query doesn't work.
2) Insert your column name for COLUMN_NAME.

Good Luck,
Tom Milewski

ryan
06-21-2005, 03:50 AM
thanks a lot. How do i display all the columns with out typing out each column name?

tmilewski
06-22-2005, 04:03 AM
sorry but you would have to do this:
echo( $row['COLUMN_NAME_1'] . $row['COLUMN_NAME_2']);
if you want to add other stuff in do this:
echo( $row['COLUMN_NAME_1'] ."SOME TEXT HERE ". $row['COLUMN_NAME_2']);
note: the periods are essential.

Good Luck,
Tom Milewski

ryan
06-23-2005, 06:43 AM
actually i saw some code i liked.


foreach ($row as $field)
{
$client1 = $field . " ";
}



now how can i add a string value to a text field or box from php?

tmilewski
06-24-2005, 12:12 AM
echo("<input name='textbox' id='textbox' value='" . $string . "' />");

echo("<textarea name='textarea' id='textarea'>" . $string . "</textarea>")

- Tom Milewski