Hi ,
i am trying to retrieve a row of data from a SQL table,but i dont get the results,i just get the variable($stock_code) that i use to search for the row on the screen.

<?php
include "dbaccess.php";
$stock_code=$_POST["txtStock"];

// Insert the required SQL query here.
$query = "SELECT STOCK_CODE FROM STOCKS WHERE STOCK_CODE = '$stock_code'";


$result = submitSQL($query, "read", 0, 0);

for ($i = 0; $i < count($result); $i++) {
// The for loop is used to display one result per row.
// Preferably use a key field for the count.
// Note: The fieldname must be UPPERCASE

// The next two lines are optional and are used only to help document the table structure
// in the resulting HTML code.
$row_number = $i + 1;


// For each row of SQL output, create a row in an HTML table and then
// add a data element for each field as required.
// Notes: 1. The \n additions are only to clean up the appearance of the HTML code
// but do not affect operation hence they are also optional.
// 2. The lines that contain $result need to have the appropriate field names
// in them in UPPERCASE.

echo "<tr>\n";
echo "<td>";
echo $result[$i];
echo "</td>\n<td>";
echo $result[$i];
echo "</td>\n<td>";
echo $result[$i];
echo "</td>\n";
echo $result[$i];
echo "</td>\n";
echo "</tr>\n";

}
?>
</table>


Any suggestions???

Recommended Answers

All 2 Replies

would it be easier to do this in a while loop?

$query = "SELECT STOCK_CODE FROM STOCKS WHERE STOCK_CODE = '$stock_code'";

while($row=mysql_fetch_assoc($query)){
echo "<tr>\n";
echo "<td>";
echo $row['STOCK_CODE'];
echo "</td>\n<td>";
echo $row['STOCK_NAME'];
echo "</td>\n<td>";
echo $row['PRICE'];
echo "</td>\n";
echo $row['QUANTITY_AVAILABLE'];
echo "</td>\n";
echo "</tr>\n";

}
?>
</table>

just a thought

if your not pulling your info i would display your query to make sure the info is correct.

echo "SELECT STOCK_CODE FROM STOCKS WHERE STOCK_CODE = '.$stock_code.'";

Try this for the SQL statement

"SELECT * FROM STOCKS WHERE STOCK_CODE = '.$stock_code.'";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.