PDA

View Full Version : Can a dynamic link be create from this loop?


mwm
05-23-2006, 08:19 PM
I'm having employees search a database that has invoices in it.
The can search by vendor, vendor invoice, check or community. What I need is either the Idnum or the imageid to be a link so when click on it can be viewed. Any idea how this can be done dynamically?

Thanks


<html>
<body>

<head><link rel=stylesheet type=text/css href=css/default.css></head>

<h1>
<p align=center></p><p align=center></center></p></h1>











<?
include ("conn1.php");

session_start();
//echo "HI";


$mysql = ("SELECT idnum, ven,veninvoice,kirkcheck,community,imageid FROM corp
WHERE ven LIKE '%$ven%'
AND veninvoice LIKE '%$veninvoice%'
AND kirkcheck LIKE '%$kirkcheck%'
AND community LIKE '%$community%'AND idnum LIKE '%$idnum%'AND imageid LIKE

'%$imageid%'

");



$result= mysql_query($mysql) or die ("Can't connect");



echo "<th>&nbsp;&nbsp; &nbsp;&nbsp;Vendor</th>";
echo "<th>&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;

&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;

Invoice</th>";
echo "<th>&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;Check</th>";
echo "<th>&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;Community</th>";



echo "<table border=\"0\">";
$j = true;
while ($row = mysql_fetch_row($result))


{
if($j)
$j= false;

else
$j=true;
echo "<tr>";

for ($i=0;$i<mysql_num_fields($result);$i++) {
if ($j) {

echo "<td bgcolor=\"#FFFFCC\">";

}
if (!$j) {

echo "<td bgcolor=\"#FFFFCC\">";
}
echo $row[$i];
echo "</td>";

}

}
echo "</table>";

?>

fci
05-23-2006, 09:26 PM
most of my time was spent making your code looking *readable*.. please observe my modifications if you expect people to help you.. also, beware of SQL injection.<html>
<body>
<head><link rel=stylesheet type=text/css href=css/default.css></head>
<h1>
<p align=center></p><p align=center></center></p></h1>
<?

include ("conn1.php");

session_start();
$sql = "
SELECT idnum, ven,veninvoice,kirkcheck,community,imageid
FROM corp
WHERE ven LIKE '%$ven%'
AND veninvoice LIKE '%$veninvoice%'
AND kirkcheck LIKE '%$kirkcheck%'
AND community LIKE '%$community%'
AND idnum LIKE '%$idnum%'
AND imageid LIKE '%$imageid%'
";


$result= mysql_query($sql) or die ("Can't connect");

?>
<table border="0">
<th>Vendor</th>
<th>Invoice</th>
<th>Check</th>
<th>Community</th>
<?php

$j = 0;

while ($row = mysql_fetch_assoc($result)) {

echo ($j++%2==0) ? '<tr bgcolor="#FFFFCC">' : '<tr bgcolor="#FFFFFF">';

echo '
<td>
<a href="'.$row['a_column_id'].'">'.$row['a_column_name'].'</a>
</td>
';

}
echo '</table>';

?>

mwm
05-24-2006, 02:09 PM
I appreciate your help, when I put in the column name the only thing that prints in the table headers.

thanks

fci
05-24-2006, 02:14 PM
try
print mysql_num_rows($result);

and, in the while loop, have:
print_r($row);

for the column name, you used one of these: idnum, ven,veninvoice,kirkcheck,community,imageid ?

mwm
05-24-2006, 03:09 PM
Yes I was using imageid. I did try what you suggested but that didn't work. Any other ideas?

thanks

fci
05-24-2006, 03:11 PM
what do you mean, "didn't work" ..did you get an error? did the mysql_num_rows print a zero? if so, then your query wouldn't be returning any results.

mwm
05-24-2006, 03:23 PM
It prints yellow lines but no results from the query. I try the query alone and it works. What do you think?

fci
05-24-2006, 03:48 PM
yellow lines? what does that mean?..


change the while loop portion to the following...

print mysql_num_rows($result);
while ($row = mysql_fetch_assoc($result)) {
print_r($row);
}

mwm
05-24-2006, 04:17 PM
Is this what you mean? If so not getting anything now. The yellow lines are a result from the table color call <tr bgcolor="#FFFFCC">. Why is this so hard to do.



<html>
<body>
<head><link rel=stylesheet type=text/css href=css/default.css></head>
<h1>
<p align=center></p><p align=center></center></p></h1>
<?

include ("conn1.php");

session_start();
$sql = "
SELECT idnum, ven,veninvoice,kirkcheck,community,imageid
FROM corp
WHERE ven LIKE '%$ven%'
AND veninvoice LIKE '%$veninvoice%'
AND kirkcheck LIKE '%$kirkcheck%'
AND community LIKE '%$community%'
AND idnum LIKE '%$idnum%'
AND imageid LIKE '%$imageid%'
";


$result= mysql_query($sql) or die ("Can't connect");

?>
<table border="0">
<th>Vendor</th>
<th>Invoice</th>
<th>Check</th>
<th>Community</th>
<?php

$j = 0;

print mysql_num_rows($result);
while ($row = mysql_fetch_assoc($result)) {
print_r($imageid);
}


echo ($j++%2==0) ? '<tr bgcolor="#FFFFCC">' : '<tr bgcolor="#FFFFFF">';

echo '
<td>
<a href="'.$row['imageid'].'">'.$row['imageid'].'</a>
</td>
';

}
echo '</table>';

?>

fci
05-24-2006, 06:39 PM
It isn't, you just don't understand what I'm saying to you.<html>
<body>
<head><link rel=stylesheet type=text/css href=css/default.css></head>
<h1>
<p align=center></p><p align=center></center></p></h1>
<?

include ("conn1.php");

session_start();
$sql = "
SELECT idnum, ven,veninvoice,kirkcheck,community,imageid
FROM corp
WHERE ven LIKE '%$ven%'
AND veninvoice LIKE '%$veninvoice%'
AND kirkcheck LIKE '%$kirkcheck%'
AND community LIKE '%$community%'
AND idnum LIKE '%$idnum%'
AND imageid LIKE '%$imageid%'
";


$result= mysql_query($sql) or die ("Can't connect");

?>
<table border="0">
<th>Vendor</th>
<th>Invoice</th>
<th>Check</th>
<th>Community</th>
<?php

print 'Total '. mysql_num_rows($result).'<br />';

while ($row = mysql_fetch_assoc($result)) {

print_r($row);

echo $row['idnum'].'<br />'.$row['ven'].'<br />'.$row['veninvoice'].'<br />'.$row['kirkcheck'].'<br />'.$row['community'].'<br />'.$row['imageid'].'<br />';
}

echo '</table>';

?>


and use the [ php ] tags or code [ code ] tags
http://www.codingforums.com/misc.php?do=bbcode