darkangel2001lv Posted February 27, 2012 Share Posted February 27, 2012 Hey guys have been trying to get this script to work for a while now, i am new to php and mysql so i am sure i am missing something simple. I have DB setup and need to pull data based on the key item code and get the following I want to get the fields item_code description allergy_statement useable_units region_availability order_lead_time ingredients for item_code 12-100 LITERALLY 12-100, no range, but like i said before i am really new to php and mysql. I have 1187 items that when a user clicks a link in search results it takes them to the product details page for that item code All that data is in my database just can't figure out how to get it out of the database. Is this even the right script to achieve that result. here is the code to get the data from database <?php require_once('includes/mysql_connect_nfacts_ro.php'); $query = "SELECT item_code, description, allergy_statement, useable_units, region_availability, order_lead_time, ingredients " . "FROM products " . "WHERE item_code = '12-100' "; $resuts = mysql_query($query) or die(mysql_error()); ?> And need to display the data like so : <td width="715" align="center" valign="top"> <h1>Product Details</h1> <h3>DISPLAY description HERE</h3> <table width="420" border="0"> <td class="ingreg"> </td> </table> <h5>Item Number</h5> <table width="420" border="0"> <tr> <td class="ingreg">DISPLAY ITEM_CODE HERE</td> </tr> </table> <h3>Ingredients:</h3> <table width="420" border="0"> <tr> <td class="ingreg">DISPLAY INGREDIENTS HERE</td> </tr> </table> <h4>Allergy Statement:</h4> <table width="420" border="0"> <tr> <td class="ingreg">DISPLAY Allergy Statement HERE</td> </tr> </table> <h4>Useable Units Per Package:</h4> <table width="420" border="0"> <tr> <td class="ingreg">DISPLAY Useable Units Per Package HERE</td> </tr> </table> <h4>Region Availability: </h4> <table width="420" border="0"> <tr> <td class="ingreg">&DISPLAY ITEM_CODE HERE</td> </tr> </table> <h4>Order Lead Time:</h4> <table width="420" border="0"> <tr> <td class="ingreg">&DISPLAY order lead time HERE</td> </tr> </table> <p> </p> <div align="right"></div></td> </tr> </table> how do i get data in database to display where i need it to? Can any one shine some light on this Quote Link to comment https://forums.phpfreaks.com/topic/257891-need-help-with-displaying-mysql-data/ Share on other sites More sharing options...
blacknight Posted February 27, 2012 Share Posted February 27, 2012 you use the fallowing code to set the data returned as a object var example $data = mysql_fetch_array($result); then you can return the data as $data['item_code'] and so on and so on Quote Link to comment https://forums.phpfreaks.com/topic/257891-need-help-with-displaying-mysql-data/#findComment-1321845 Share on other sites More sharing options...
darkangel2001lv Posted February 27, 2012 Author Share Posted February 27, 2012 ok added code $data = mysql_fetch_array($result); <?php require_once('connection file'); $query = "SELECT item_code, description, allergy_statement, useable_units, region_availability, order_lead_time, ingredients " . "FROM products " . "WHERE item_code = '12-100' "; $resuts = mysql_query($query) or die(mysql_error()); $data = mysql_fetch_array($result); ?> and to display the data where i need it to <table width="889" border="0"> <tr> <td width="231"><p><img src="images/12-100.jpg" width="231" height="547"></p> <p><iframe src='includes/product-disclaimer.php' frameborder='0' width='100%' height='150' ></iframe></td> <td width="715" align="center" valign="top"> <h1>Product Details</h1> <h3>#</h3> <table width="420" border="0"> <td class="ingreg"> </td> </table> <h5>Item Number</h5> <table width="420" border="0"> <tr> <td class="ingreg"><?php echo $data['item_code'] ?></td> </tr> </table> i get nothing back the data is there, connection is fine but not displaying. Is there somewhere i can got to figure this out. Sorry if this is really simple , but i am very new to php and mysql, and have been trying for a week to get this one script to work. Need to figure out asap. Deadline to meet. I am confussed, Quote Link to comment https://forums.phpfreaks.com/topic/257891-need-help-with-displaying-mysql-data/#findComment-1321852 Share on other sites More sharing options...
bspace Posted February 27, 2012 Share Posted February 27, 2012 $resuts $result note the difference Quote Link to comment https://forums.phpfreaks.com/topic/257891-need-help-with-displaying-mysql-data/#findComment-1321858 Share on other sites More sharing options...
DavidAM Posted February 28, 2012 Share Posted February 28, 2012 you use the fallowing code to set the data returned as a object var example $data = mysql_fetch_array($result); then you can return the data as $data['item_code'] and so on and so on Just for the record, $data is an array variable not an object variable. Quote Link to comment https://forums.phpfreaks.com/topic/257891-need-help-with-displaying-mysql-data/#findComment-1321861 Share on other sites More sharing options...
darkangel2001lv Posted February 28, 2012 Author Share Posted February 28, 2012 I haven fixed the typo but still can't get script to work. i get the following error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/content/84/8829884/html/products/12-100-2.php on line 11 line 11 is the following: $data= mysql_fetch_array($result); I am new to php and mysql, i need to get this script working otherwise i have to create 1187 different product details page one by one in less than two weeks. This is pointless when all that data is already stored in a database. I have tried for over a week to get this working and frankly i am thinking i have wasted a week. this site that i am working on launches in two weeks, i need to get this working ASAP. Please can someone help me understand why my script isn't working and what do i have to do to it to display the data where i need it to (see earlier post.) Quote Link to comment https://forums.phpfreaks.com/topic/257891-need-help-with-displaying-mysql-data/#findComment-1321871 Share on other sites More sharing options...
DavidAM Posted February 28, 2012 Share Posted February 28, 2012 I haven fixed the typo but still can't get script to work. i get the following error: That error is telling you exactly the same thing that bspace told you in Reply #3. Fix that "typo" if you want to retrieve the data from the query. You stored the query resource in $results, you have to fetch it from that variable: $resuts = mysql_query($query) or die(mysql_error()); $data = mysql_fetch_array($results); Quote Link to comment https://forums.phpfreaks.com/topic/257891-need-help-with-displaying-mysql-data/#findComment-1321875 Share on other sites More sharing options...
darkangel2001lv Posted February 28, 2012 Author Share Posted February 28, 2012 thanks guys with your help finally got it working. Quote Link to comment https://forums.phpfreaks.com/topic/257891-need-help-with-displaying-mysql-data/#findComment-1321895 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.