Discussions Search    Reviews    Search Aid    Buzzzz    Google@Omgili    Q&A    Health Add to iGoogle   Bookmark and Share

  Advanced Search

Welcome to Omgili,
Omgili (Oh My God I Love It ;) is a search engine for discussions. With Omgili you can find answers and solutions, debates, discussions, personal experiences, opinions and more... To learn more about Omgili click here.

This is a complete preview of the discussion as it was indexed by Omgili crawlers. Use this preview if the original discussion is unavailable.
Click here to view the original discussion.
[http://www.codingforums.com/showthread.php?t=145...]

Click here to search for discussions with Omgili discussions search engine.

mysql_fetch_array(): supplied argument is not a valid MySQL result resource - CodingForums.com

Please help me...

Here is the first part of the offending code. PHP Code: if(isset($_REQUEST['complete'])){ $order_complete_qry="UPDATEordersSETorder_status='2'WHEREorder_id=$oid[order_id]"; $result=mysql_query($order_complete_qry)ordie("Cannotcompleteorder:".mysql_error()); this works fine and updates the DB appropriately the following code immediately follows in the script as well PHP Code: //seriesofqueriestoupdatestock //thisqueryshouldgetallstockitemsaddedtoorderbyuser $current_order_qry="SELECTitem_idFROMorderitemsWHEREorder_id=$oid[order_id]ORDERBYitem_id"; $order_result="mysql_query($current_order_qry)ordie(\"Cannotgetitemsonorder:\".mysql_error())"; while($orderitems=mysql_fetch_array($order_result)){ $itemids[]=$orderitems; } this on gets a "mysql_fetch_array(): supplied argument is not a valid MySQL result resource in..." error.

The update statement is designed to only pull one record and the select should draw multiples.

I think therein lies the problem but im obviously not sure.

Please help a pathetic newbie.

If there is not enough code here let me know and I can post more I just didn't want to write a book for people to have to read.

You're putting the whole command in Quote: s so it's a string - that's really not what you want. This: PHP Code: //seriesofqueriestoupdatestock //thisqueryshouldgetallstockitemsaddedtoorderbyuser $current_order_qry="SELECTitem_idFROMorderitemsWHEREorder_id=$oid[order_id]ORDERBYitem_id"; $order_result="mysql_query($current_order_qry)ordie(\"Cannotgetitemsonorder:\".mysql_error())"; while($orderitems=mysql_fetch_array($order_result)){ $itemids[]=$orderitems; } Should be this: PHP Code: //seriesofqueriestoupdatestock //thisqueryshouldgetallstockitemsaddedtoorderbyuser $current_order_qry="SELECTitem_idFROMorderitemsWHEREorder_id=$oid[order_id]ORDERBYitem_id"; $order_result=mysql_query($current_order_qry)ordie("Cannotgetitemsonorder:".mysql_error()); while($orderitems=mysql_fetch_array($order_result)){ $itemids[]=$orderitems; } You should consider using a syntax highlighting editor - these simple errors tend to stick out better.

Please, put your code between [ php] and [ /php] or [ code] and [ /code] tags.

You can edit your posts, thank you. try this: PHP Code: //seriesofqueriestoupdatestock //thisqueryshouldgetallstockitemsaddedtoorderbyuser $current_order_qry="SELECTitem_idFROMorderitemsWHEREorder_id=$oid[order_id]ORDERBYitem_id"; $order_result=mysql_query($current_order_qry)ordie("Cannotgetitemsonorder:".mysql_error()); if($order_result){ while($orderitems=mysql_fetch_array($order_result)){ $itemids[]=$orderitems; } }else{ printmysql_error(); } regards

I just noticed the thing about the php tags but thanks for letting me know and thanks for the help as well.

Ok we are much closer now thank you but i still have one problem... PHP Code: echo"Theitemsontheorderare".".$itemids.".""; printf("Theitemsontheorderare:%s",$itemids[item_id]); the first line outputs array and the second one nothing at all.

Is it possible to echo the items like this or does it have to be a print_r statement instead?

PHP Code: echo"Theitemsontheorderare".$itemids['item_id']; regards

Thank you for your help.

I always want to use the "thank user for this helpful post" but then it says to make sure that a lot of thought and effort went into the post I dont feel like it took a lot of effort for you to answer my easy question but I still really appreciate it so what is the standard etiquette?

Thanks one way or the other.

I copied and pasted your code and i still get "The items on the order are" without the Quote: s and then nothing.

If i print-r it i do get what im looking for but i need to display it to a user and then interact with sql based on the item id's it contains.

I know its getting the right data so where do i go next?

Code: while($orderitems = mysql_fetch_array($order_result)){ $itemids[]=$orderitems; Code: echo "The items on the order are".$itemids['item_id']; Just have a look in to the output of print_r($itemids) statement It'd be starting with something like Code: Array ( [0] =>

Array ( [0] ) [1] => From your code, it's clear that the array $itemids is going to be an array of array(2D), since $orderitems itself is an array(return value of mysql_fetch_array) Thus PHP Code: echo"Theitemsontheorderare"; for($i=0;$i<count($itemids);$i++) echo"<br/>".$itemids[$i]['item_id']; should give you some result.

I added the code but still no effect.

You are definately right about it being an array of arrays and I feel this is the problem but the code you offered had no output still.

The print_r statement outputs as you expect it would.

Do i need to use some kind of explode() or implode() type line or maybe a foreach instead of for statement?

Ive been trying different code bits for going on two days.

Please if you have any other suggestions please throw them out there and thanks for the help so far.