PDA

View Full Version : cannot get select statement to work, very basic one


percept
03-24-2004, 12:36 PM
Hello, I can't for the life of me figure out why my select statement will not retrieve the data from MySql. it is a very simple statment;

mysql_query ("SELECT pub_type, call_number, pub_author, pub_title, subtitle, edition, publisher, publication_year, physical_description, series, isbn, holdings, subjects FROM library WHERE id=" .$pub_id);
but when I try to echo any of these variables I get nothing showing for results. the $pub_id displays because it is set by a GET function.

echo "<b class='foo'>$pub_id $pub_author $series </b> ";

I use a select statement on the page that calls for this page and it retrieves info from the database not problem... my includes for database connection, etc are all in tact.

Any help or advice greatly appreciated!

sweenster
03-24-2004, 01:22 PM
try:


$sql = "SELECT pub_type, call_number, pub_author, pub_title, subtitle, edition, publisher, publication_year, physical_description, series, isbn, holdings, subjects FROM library WHERE id='".$pub_id."'";
$result = mysql_query($sql);


actually, why have you named all these rows? would you not be quicker doing:

$sql = "SELECT * FROM library WHERE id='".$pub_id."'";
$result = mysql_query($sql);

percept
03-24-2004, 01:33 PM
Thanks sweenster, I listed all the columns just because I'm exhausting all possibilities. I had the wildcard in the select for several attempts.

I tried your example and still no results. I've tried a few variances of the select statement and get nothing.

I've assigned the "@" symbol to all my sql queries to make sure I'm getting a database connection, I am, and when it reaches my select statemtent, the error message tells me it is a query problem. But I just don't get it... there is nothing wrong with the code as I can see it.

I'm wondering if this has anything to do with using sessions?

Thanks

raf
03-24-2004, 04:38 PM
you should never use

select * from table ..

inside embedded sql. Not even if you would need all columns. As soon as you would then add a column to your db, your recordset would be to big, which is just a waste of runtime resources. Alsways keep the size of your recordset as small as possible. Select * is only usefull when debugging or when you do some DBA work and you quickly need the records, but inside your applications, it can only be usefull if you have some generic code and you'll select all columns and then process then inside some

for ($i=0; $i < mysql_num_fields($result); $i++){
...
}


About the actual problem --> check your mail.
+ you don't give the code you use to proces the recordset, which is actually what we need.