selecting columns

A

Anonymous

Guest
Hi!,

I am trying to select data from two different columns and print both to html link. The code i have so far goes as follows..

$searchdata = $_GET['query'];
mysql_connect($mysqlserver1, $mysqluser, $mysqlpass) or die ("Unable to connect to MySQL server.");
mysql_select_db ("psa");
$result = mysql_query ("select id, pname from clients where pname like '%$searchdata%'") or die ("Unable to select requested table.");
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$querydata1[] = $row["pname"];
$iddata[] = $row["id"];
}
I want to print the results to a link like so...

$box = array_merge ($querydata1, $querydata2, $querydata3);
sort ($box);
foreach($box as $client) {
print "<table border='0' cellpadding='0' cellspacing='0' width='100%'>";
print "<tr>";
print "\t\t<font face=\"Arial\" size=\"1\" color=red><a href='client.php?client=$client?id=$id'>$client</a></font><br>\n";
}

I have no problem with the $client variable but can't seem to match up the $id with the $client

Any help will be greatly appreciated!

TIA...
 
I think you are complicating things a little.

if you just want to output a bunch of links from an array I would use multidimensional arrays opposed to merging arrays.

Code:
$searchdata = $_GET['query'];
mysql_connect($mysqlserver1, $mysqluser, $mysqlpass) or die ("Unable to connect to MySQL server.");
mysql_select_db ("psa");
$result = mysql_query ("select id, pname from clients where pname like '%$searchdata%' order by pname asc") or die ("Unable to select requested table.");
$count = 0;
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$querydata[$count]['pname'] = $row["pname"];
$querydata[$count]['id'] = $row["id"];
$count++;
} 

for($x=0; $x<sizeof($querydata); $x++)
{
print "<table border='0' cellpadding='0' cellspacing='0' width='100%'>";
print "<tr>";
print "\t\t".'<font face="Arial" size="1" color=red><a href="client.php?client='.$querydata[$x]['pname'].'&id='.$querydata[$x]['id'].'">'.$querydata[$x]['pname'].'</a></font><br>'."\n";
}
 
Back
Top