selecting columns

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

startech
New php-forum User
New php-forum User
Posts: 12
Joined: Mon Jun 30, 2003 10:54 am

selecting columns

Postby startech » Mon Jul 28, 2003 11:15 am

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...

User avatar
Redcircle
Moderator
Moderator
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA
Contact:

Postby Redcircle » Wed Jul 30, 2003 12:11 pm

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: Select all

$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";
}


Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 1 guest