Titan85
02-05-2007, 06:38 PM
Hello, I am attempting to make a page that will display all the jobs that have been done for a certain user and give them a link to download the files for each job. I have it mostly working, but ran into a small error. The error is that ecen though my sql query returns results, they are not displayed. Here is my code:
<?php
$user = $_SESSION['user'];
// Query to get client data
$sql = "SELECT * FROM `jobs` WHERE username = '$user' ORDER BY id DESC";
$result = mysql_query($sql) or die ('Error Getting Job Data! <br />' .mysql_error());
// Get number of results
$results = mysql_num_rows($result);
// Put data in array
$row = mysql_fetch_array($result);
// If no results found
if($results < 1) {
echo '
You have no files to download because no jobs have been done for you. Click <a href="http://echo-designes.com/contact.php">here</a> to have a job done.
';
}
// If there are results
if($results >= 1) {
echo '
<b>Select the files you would like to download.</b>
<br /><br />';
// For each result found
while($row = mysql_fetch_array($result)) {
extract($row);
echo '
<a href="'.$download.'">'.$title.'</a>
<br />';
}
}
?>When I take out the while statement and just use
echo '
<a href="'.$row['download'].'">'.$row['title'].'</a>
<br />';It works fine. But because I want there to be multiple links, I need to use the while statement. Any ideas?
EDIT: I removed the first $row = mysql_fetch_array($result); statement and it worked. But for another script, I need to get the data from the query before I run my while statement, any way to do that?
<?php
$user = $_SESSION['user'];
// Query to get client data
$sql = "SELECT * FROM `jobs` WHERE username = '$user' ORDER BY id DESC";
$result = mysql_query($sql) or die ('Error Getting Job Data! <br />' .mysql_error());
// Get number of results
$results = mysql_num_rows($result);
// Put data in array
$row = mysql_fetch_array($result);
// If no results found
if($results < 1) {
echo '
You have no files to download because no jobs have been done for you. Click <a href="http://echo-designes.com/contact.php">here</a> to have a job done.
';
}
// If there are results
if($results >= 1) {
echo '
<b>Select the files you would like to download.</b>
<br /><br />';
// For each result found
while($row = mysql_fetch_array($result)) {
extract($row);
echo '
<a href="'.$download.'">'.$title.'</a>
<br />';
}
}
?>When I take out the while statement and just use
echo '
<a href="'.$row['download'].'">'.$row['title'].'</a>
<br />';It works fine. But because I want there to be multiple links, I need to use the while statement. Any ideas?
EDIT: I removed the first $row = mysql_fetch_array($result); statement and it worked. But for another script, I need to get the data from the query before I run my while statement, any way to do that?