Jump to content

So frustrated trying to display record.


ignorant

Recommended Posts

I am trying to display on record, two fields of the record.

 

here is what I'm using:

 

<?php require_once('../Connections/connectionpage.php'); ?>

<?php

  mysql_select_db($database, $db) or die(mysql_error());

$Booth_Num = $_GET['WLE_booth'];

$Company_Nam = $_GET['Company'];

$Booth_Num = mysql_real_escape_string($Booth_Num);

$Company_Nam = mysql_real_escape_string($Company_Nam);

$query = "SELECT * FROM tablename WHERE WLE_booth = '$Booth_Num'";

$qry_result = mysql_query($query) or die(mysql_error());

 

$display_string = "<table>";

$display_string .= "<tr>";

$display_string .= "<th>Booth</th>";

$display_string .= "<th>Company</th>";

$display_string .= "</tr>";

 

while($row = mysql_fetch_array($qry_result)){

$display_string .= "<tr>";

$display_string .= "<td>$Booth_Num</td>";

$display_string .= "<td>$Company_Nam</td>";

$display_string .= "</tr>";

 

}

$display_string .= "</table>";

echo $display_string;

 

?>

 

Please help me before my boss fires me...

Link to comment
Share on other sites

I don't understand. You did a query, then used a while loop with that query, but your not even using that query within the while loop...that doesn't make sense to me. If your only expecting one result, then there is no need for a loop.

 

<?php 
require_once('../Connections/connectionpage.php');

mysql_select_db($database, $db) or die(mysql_error());
$Booth_Num = $_GET['WLE_booth'];
$Company_Nam = $_GET['Company'];
$Booth_Num = mysql_real_escape_string($Booth_Num);
$Company_Nam = mysql_real_escape_string($Company_Nam);
$query = "SELECT * FROM tablename WHERE WLE_booth = '$Booth_Num'";
$qry_result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_assoc($qry_result);

$display_string = "<table>";
$display_string .= "<tr>";
$display_string .= "<th>Booth</th>";
$display_string .= "<th>Company</th>";
$display_string .= "</tr>";
$display_string .= "<tr>";
$display_string .= "<td>{$row['booth_num']}</td>";
$display_string .= "<td>{$row['company_nam']}</td>";
$display_string .= "</tr>";
$display_string .= "</table>";

echo $display_string;
   
?>

 

Obviously you will need to fill in your own column name values from your database on the two variables I used. I'm not sure if this is what your looking for, but you can give it a try.

 

 

Link to comment
Share on other sites

Yeah I'm new at this and trying to learn from a book and code snips. Your code doesn't give me an error, but it doesn't display anything. I know the field names are correct, but it just doesn't display anything. I'm getting frustrated.

 

 

I don't understand. You did a query, then used a while loop with that query, but your not even using that query within the while loop...that doesn't make sense to me. If your only expecting one result, then there is no need for a loop.

 

 

Obviously you will need to fill in your own column name values from your database on the two variables I used. I'm not sure if this is what your looking for, but you can give it a try.

 

 

Link to comment
Share on other sites

You want something like this.

 

<?php require_once('../Connections/connectionpage.php'); ?>
<?php
// connect to database
  mysql_select_db($database, $db) or die(mysql_error());

$Booth_Num = $_GET['WLE_booth'];
$Company_Nam = $_GET['Company'];
$Booth_Num = mysql_real_escape_string($Booth_Num);
$Company_Nam = mysql_real_escape_string($Company_Nam);
$query = "SELECT * FROM tablename WHERE WLE_booth = '$Booth_Num'";
$qry_result = mysql_query($query) or die(mysql_error());

$display_string = "<table>";
$display_string .= "<tr>";
$display_string .= "<th>Booth</th>";
$display_string .= "<th>Company</th>";
$display_string .= "</tr>";

while($row = mysql_fetch_assoc($qry_result)){
    // $Booth_Num and $Company_Nam still contain GET data
    // $row contains data retrieved from the database
    // you need to actually reference $row to use any of that data
    $display_string .= "<tr>";
    $display_string .= "<td>$row[WLE_booth]</td>";
    $display_string .= "<td>$row[company_name]</td>";
    $display_string .= "</tr>";
   
}
$display_string .= "</table>";
echo $display_string;
   
?>

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.