Guest Posted March 9, 2004 Posted March 9, 2004 I have added a new table to my database, and everything works well. However on the admin/index page I basically want to show a simple bit of text if there is anything in this table. I have the following php code in my index page. $shipping_quote = tep_db_query("select count(*) from " . TABLE_REQUEST_SHIPPING); if ($shipping_quote['total'] < 0 ) { } else { echo ('<table border="0" width="100%" cellspacing="0" cellpadding="2"> <tr class="infoBox"> <td class="infoBox">Quotes Waiting</td> </tr> </table>'); } However the "Quotes shipping" shows up if there are items in this table or not! I cant work out what I am doing wrong.
♥yesudo Posted March 9, 2004 Posted March 9, 2004 if ($shipping_quote['total'] <= 0 ) Your online success is Paramount.
♥yesudo Posted March 10, 2004 Posted March 10, 2004 if ($shipping_quote['total'] = Null) or try echoing what the query returns when the table is empty. Your online success is Paramount.
Mark Evans Posted March 10, 2004 Posted March 10, 2004 Hi Paul Try the following $shipping_quote_query = tep_db_query("select count(*) as total from " . TABLE_REQUEST_SHIPPING)); $shipping_quote = tep_db_fetch_array($shipping_quote_query); if ($shipping_quote['total'] > 0 ) { echo ('<table border="0" width="100%" cellspacing="0" cellpadding="2"> <tr class="infoBox"> <td class="infoBox">Quotes Waiting</td> </tr> </table>'); } That should do it :) Mark Evans osCommerce Monkey & Lead Guitarist for "Sparky + the Monkeys" (Album on sale in all good record shops) --------------------------------------- Software is like sex: It's better when it's free. (Linus Torvalds)
Guest Posted March 10, 2004 Posted March 10, 2004 Mark, I tried what you reccomended but got a parse error on line 132 which is CSS lines of admin/index so im not sure what happened there. I I removed one of the double ) and that seemed to work. THi is what i mean $shipping_quote_query = tep_db_query("select count(*) as total from " . TABLE_REQUEST_SHIPPING); $shipping_quote = tep_db_fetch_array($shipping_quote_query); if ($shipping_quote['total'] > 0 ) { echo ('<table border="0" width="100%" cellspacing="0" cellpadding="2"> <tr class="infoBox"> <td class="infoBox">Quotes Waiting</td> </tr> </table>'); } However after running it I still get the quotes waiting text even though the table is empty. I echoed shipping_quote and just got 'Array' returned. If i try Emmets suggestion with if ($shipping_quote['total'] <= 0 ) echoing shipping_quote returns 'Resource id#32' if i try if ($shipping_quote['total'] = Null) and echo Shiping_quote I get 'Warning: Cannot use a scalar value as an array in /home/penlan/public_html/admin/index.php on line 133' Any ideas.
Guest Posted March 10, 2004 Posted March 10, 2004 In case anyone is as lost as me, here is a run down of everything I have done so far.You will notice that i have added the echo shipping_quote to see what is being output. $shipping_quote = tep_db_query("select count(*) from " . TABLE_REQUEST_SHIPPING); if ($shipping_quote == 0 ) { } else { echo ('<table border="0" width="100%" cellspacing="0" cellpadding="2"> <tr class="infoBox"> <td class="infoBox">Quotes Waiting</td> </tr> </table>'); } echo($shipping_quote); With an empty table the text still showed up, also echo output this "Resource id #32" I also have tried a few other things, which have the same results. But different outputs with the echo. $shipping_quote_query = tep_db_query("select count(*) as total from " . TABLE_REQUEST_SHIPPING); $shipping_quote = tep_db_fetch_array($shipping_quote_query); if ($shipping_quote['total'] > 0 ) { echo ('<table border="0" width="100%" cellspacing="0" cellpadding="2"> <tr class="infoBox"> <td class="infoBox">Quotes Waiting</td> </tr> </table>'); } echo($shipping_quote); Text shows and the echo outputs "array" I also tried $shipping_quote = tep_db_query("select count(*) from " . TABLE_REQUEST_SHIPPING); if ($shipping_quote <= 0 ) { } else { echo ('<table border="0" width="100%" cellspacing="0" cellpadding="2"> <tr class="infoBox"> <td class="infoBox">Quotes Waiting</td> </tr> </table>'); } echo($shipping_quote); Then the echo returns "Resource ID#32" and the text shows If i try $shipping_quote = tep_db_query("select count(*) from " . TABLE_REQUEST_SHIPPING); if ($shipping_quote = Null) { } else { echo ('<table border="0" width="100%" cellspacing="0" cellpadding="2"> <tr class="infoBox"> <td class="infoBox">Quotes Waiting</td> </tr> </table>'); } echo($shipping_quote); Then the echo returns nothing at all except the text quotes waiting. If i replace the IF statement with "if ($shipping_quote['total'] = Null)" I then get the text and "'Warning: Cannot use a scalar value as an array in /home/penlan/public_html/admin/index.php on line 133'" Line 133 is nowhere near the bit of code I am putting in, its a CSS style that appears in the heading of the page. I also tried $shipping_quote = tep_db_query("select count(*) from " . TABLE_REQUEST_SHIPPING); if ($shipping_quote < 1 ) { } else { echo ('<table border="0" width="100%" cellspacing="0" cellpadding="2"> <tr class="infoBox"> <td class="infoBox">Quotes Waiting</td> </tr> </table>'); } echo($shipping_quote); and again i get the echo returns "Resource ID#32" and the text even though the table it empty
Mark Evans Posted March 10, 2004 Posted March 10, 2004 Hi Paul WHat happens when you try this $shipping_quote_query = tep_db_query("select count(*) as total from ?" . TABLE_REQUEST_SHIPPING); $shipping_quote = tep_db_fetch_array($shipping_quote_query); if ($shipping_quote['total'] ?> 0 ) { echo ('<table border="0" width="100%" cellspacing="0" cellpadding="2"> <tr class="infoBox"> ? <td class="infoBox">Quotes Waiting</td> </tr> </table>'); } var_dump($shipping_quote); That should tell you whats in the array. Mark Evans osCommerce Monkey & Lead Guitarist for "Sparky + the Monkeys" (Album on sale in all good record shops) --------------------------------------- Software is like sex: It's better when it's free. (Linus Torvalds)
Guest Posted March 10, 2004 Posted March 10, 2004 Ok the tables empty, but I still get the text. I also get this "array(1) { ["total"]=> string(1) "1" } "
♥yesudo Posted March 10, 2004 Posted March 10, 2004 try mysql.com - and let us know as I am interested in this ongoing saga. http://www.mysql.com/documentation/maxdb/4...261/content.htm http://www.mysql.com/documentation/maxdb/4...261/content.htm Your online success is Paramount.
Guest Posted March 10, 2004 Posted March 10, 2004 Do you want me to list a bit more of the index.php so you can see where i am including it, and also the table details?
Guest Posted March 11, 2004 Posted March 11, 2004 Ok I feel a duffos. Although I emptied the database table, half way through testing all of this someone put a quote through and put a item into the table :rolleyes: . So I thought the table was empty and it wasnt. After some re-testing I found this code definitely works ok. $shipping_quote_query = tep_db_query("select count(*) as total from " . TABLE_REQUEST_SHIPPING); $shipping_quote = tep_db_fetch_array($shipping_quote_query); if ($shipping_quote['total'] > 0 ) { echo ('<table border="0" width="100%" cellspacing="0" cellpadding="2"> <tr class="infoBox"> <td class="infoBox">Quotes Waiting</td> </tr> </table>'); } Sorry for all the hassles!! One thing that would be good though is to list the number the items in this table. I tried to add echo ($shipping_quote); but that just brings up ARRAY. Can someone tell me how I can have the text above to read "Quotes Waiting 2" or however many are in the table. Thanks for your help so far guys. rgds Paul
♥yesudo Posted March 11, 2004 Posted March 11, 2004 echo ($shipping_quote['total']); Your online success is Paramount.
Guest Posted March 11, 2004 Posted March 11, 2004 Thanks very much very helpfull. I hope i can return the favour sometime. rgds Paul
Recommended Posts
Archived
This topic is now archived and is closed to further replies.