Hey guys,
I’m new to the forum and somewhat new to PHP/SQL programming. I have a question and code snippet I’d like to get some help with.
Here’s the code:
[code]<?php
$dbhost = “localhost”;
$dbuser = “username”;
$dbpass = “pass”;
$dbname = “db_table”;
//Connect to MySQL Server
$link = mysql_connect($dbhost, $dbuser, $dbpass);
//Select Database
mysql_select_db($dbname) or die(mysql_error());
// Retrieve data from Query String
$id = $_GET[‘id’];
$name = $_GET[‘name’];
$zip = $_GET[‘zip’];
$phone = $_GET[‘phone’];
$server_url = $_GET[‘server_url’];
$day = $_GET[‘day’];
$time = $_GET[‘time’];
$time1 = $_GET[‘time1’];
// Escape User Input to help prevent SQL Injection
$id = mysql_real_escape_string($id);
$name = mysql_real_escape_string($name);
$zip = mysql_real_escape_string($zip);
$phone = mysql_real_escape_string($phone);
$server_url = mysql_real_escape_string($server_url);
$day = mysql_real_escape_string($day);
$time = mysql_real_escape_string($time);
$time1 = mysql_real_escape_string($time1);
//build query
$query = “SELECT * FROM $day,sip_data WHERE $day.id=sip_data.id AND $day$time<=>$day$time1 ORDER BY zip”;
//Execute query
$qry_result = mysql_query($query) or die((‘No Results’));
if ( mysql_query( $query ) > 0 )
{
}
else
{
echo ‘No Result’;
}
//Build Result String
while($row = mysql_fetch_array($qry_result)){
$display_string .= “
$row[zip] | ”;
---|
$row[name] | ”;
}
echo $display_string;
?>
[/code]
Basically, this code will produce a table that repeats cells horizontally with data from the DB.
What I would like to do is set it so: if the $zip variable is repeated or referenced more than once in the $qry_result, the results will all appear in the same column and not repeat the same zip code twice.
Gotta head to work, but thanks in advance! Will check in again after work.