My site is , pick a guy from the drop down menu, and submit, and see all his skate sponsors.
I have 2 pages, the search form page and the php page that processes it.
My database is set up like this:
p[id,fname,lname]
c[id,company]
s[pid,cid,start,end]
here is the search page
<html>
<body>
<h2>Adding a new sponsor for a
<FORM action="search.php" method="POST">
<table border="1">
<tr>
<td>Name</td>
<td>
<?php
// Updating the database
// by Haroon Khalid and Barry Ambrose
// date Jan.30.06
// Connecting to database
include 'connect.php';
// Select fields from the person table to populate drop down menu
$result = mysql_query("SELECT * FROM p");
// Generating drop down menu from previous sql query
// by Barry Ambrose
$select_option = "<select name=\"ID\">";
while ($row = mysql_fetch_array($result)){
$select_option .= "<option value=\"".$row['id']."\">".$row['fname']." ".$row['lname']."</option>\n";
}
$select_option .= "</select>";
echo $select_option;
?>
</td>
<tr>
<td colspan="2" align="right">
<input type="submit">
</td>
</FORM>
</body>
</html>
The processing page
<?php
// Searching the database
// by Haroon Khalid and Brett Patterson
// date Jan/2006
// Connecting to the database
include 'connect.php';
// Var for perons ID from the search form
$ID = $_POST['ID'];
// Query for persons info based off ID
$query = "SELECT s.start, s.end, CONCAT(p.fname, ' ', p.lname ) AS p_name, c.company
FROM s
INNER JOIN p ON s.pid = p.id
INNER JOIN c ON s.cid = c.id
WHERE p.id = '".$_POST['ID']."'
ORDER BY s.start ASC";
$result = mysql_query($query);
// Use this for record check
$rows = mysql_num_rows($result);
$person = mysql_result($result, 0, 'p_name');
$company = mysql_result($result, 0, 'company');
$start = mysql_result($result, 0, 'start');
$end = mysql_result($result, 0, 'end');
// Printing out data
if ($rows < 1){
echo "NO RECORDS FOUND!";
}else{
// This stuff prints out but while loops doesnt do anything!
echo "$person<br>";
echo "$company<br>";
echo "$start<br>";
echo "$end<br>";
echo "Total: $rows records<br>";
echo "done<br><br>";
while($row = mysql_fetch_assoc($result))
{
echo 'Company: '.$row['company'].'<br>Spanning: '.$row['start'].' to '.$row['end'].'<br><br>';
}
}
?>
now I want it to print like:
Bryan Herman
Company: Baker Skateboards
Spanning: 20031212 to 20051212
Company: Emerica Shoes
Spanning: 20011212 to 20021212
Now the problem is that my page does print anything. So I added this section as you can see in the processing page that makes sure the query goes thru, and it does as it does print out some guys info. This is the part that I added to make sure it actually gets data:
$person = mysql_result($result, 0, 'p_name');
$company = mysql_result($result, 0, 'company');
$start = mysql_result($result, 0, 'start');
$end = mysql_result($result, 0, 'end');
// Printing out data
if ($rows < 1){
echo "NO RECORDS FOUND!";
}else{
// This stuff prints out but while loops doesnt do anything!
echo "$person<br>";
echo "$company<br>";
echo "$start<br>";
echo "$end<br>";
echo "Total: $rows records<br>";
echo "done<br><br>";
But the echo loop below does nothing, I want this one to be the main part that prints out data and it doesnt. If I dont have the added code above, then all I get is a blank page.
echo 'Company: '.$row['company'].'<br>Spanning: '.$row['start'].' to '.$row['end'].'<br><br>';
Why isnt this echo loop working?