Jump to content

Need help with displaying MySQL data


darkangel2001lv

Recommended Posts

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

Link to comment
Share on other sites

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,

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.)

Link to comment
Share on other sites

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);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.