SitePoint Sponsor |
|
User Tag List
Results 1 to 8 of 8
-
Jun 24, 2007, 11:03 #1
- Join Date
- Oct 2004
- Location
- uk
- Posts
- 853
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
variables displaying many times on same page
Hi guys
Had this problem a couple of times
Some variables are appearing several times
here is 1 example
http://www.notexperienced.co.uk/listings.php?id=22
This has also happened on other parts of the site
Why could this be?
-
Jun 24, 2007, 11:37 #2
- Join Date
- Feb 2003
- Location
- Slave I
- Posts
- 23,424
- Mentioned
- 2 Post(s)
- Tagged
- 1 Thread(s)
Without seeing code I would have to guess that you have a loop being executed. Find the spot where that variable is being echoed and check its value. If it is wrong find the place before it and see its value there. Keep backtracking until you find where it is being corrupted.
-
Jun 24, 2007, 11:47 #3
- Join Date
- Oct 2004
- Location
- uk
- Posts
- 853
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
PHP Code:<?php
session_start() ;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<?php include ("header.php") ?>
<?php include ("nav3.php") ?>
<div id="main">
<div class="featured">
<p>Recruiting now...</p>
</div>
<div id="content">
<p class="title"></p>
<FONT SIZE="3" face="century gothic">
<?php
//connect to your database ** EDIT REQUIRED HERE **
mysql_connect("localhost","notexper_two","three"); //(host, username, password)
//specify database ** EDIT REQUIRED HERE **
mysql_select_db("notexper_one") or die("Unable to select database"); //select which database we're using
$id = $_GET['id'];
$sql = " select * from jobs where id=$id";
$result = mysql_query ($sql);
while ($row = mysql_fetch_array($result))
{
$field1= $row["jobtitle"];
$field2= $row["jobdescription"];
$field3= $row["location"];
$field4= $row["category"];
$field5= $row["salary"];
$field6= $row["firstname"];
$field7= $row["surname"];
$field8= $row["email"];
$field9= $row["telephone"];
$field10= $row["jobstatus"];
$field11= $row["company"];
$field13= $row["applications"];
$field14= $row["sublocation"];
$field15= $row["id"];
echo "<title>$field1</title>";
echo "<table width=100%><tr><td valign=top><font size=4 ><b>$field1</b></center></td><td align=right>job id:<B>$field15</b></td></tr></table><bR>";
echo "<table width=100%><tr><td width=58% valign=top>$field2</td><Td align=right valign=top>
<Table><tr><td><img src=http://www.notexperienced.co.uk/images/add.gif></td><td valign=top>
- <a href=savejob.php?id=" . $id . ">Add to my jobs</a></td></tr>
<Tr><td><img src=http://www.notexperienced.co.uk/images/mail.gif></td><Td><a href=tellafriend.php?id=" . $id . ">Send to a friend</a></td></tr>
<Tr><td><img src=http://www.notexperienced.co.uk/images/print.gif onClick=window.print()></td><td>- <a href=>Print This Page</a></td></tr>
<Tr><td><img src=http://www.notexperienced.co.uk/images/apply.gif></td><td> <a href=apply.php?id=" . $id . ">Apply for this job</a></td></tr></table><Br><Br>";
echo "<font size=3 ><b>Category:</b> $field4<br>";
echo "<font size=3 ><b>Location:</b> $field14, $field3</b> <br><a href='http://maps.google.com/maps?f=q&hl=en&q=rm64px'>View Map</a><br>";
echo "<font size=3 ><b>Salary:</b> $field5</b><br>";
echo "<font size=3 ><b>Job Status:</b> $field10</b><br>";
echo "<font size=3 ><b>Applications:</b> $field13</b><br>";
echo ;
echo "<font size=3 ><b>Date Added:</b>";
$query="select *, date_format(startdate,'%D %b %Y') as MyDate from jobs";
$result=@mysql_query($query);
if(@mysql_num_rows($result) > 0)
{
while($row_articals=@mysql_fetch_array($result))
{
echo $row_articals['MyDate'] . "<br>";
}
}
echo " </b><br>
</td>
</tr>
</table>
<br>
<font size=4 ><b>Contact Details</b>
<br>
<font size=2>If you wish to apply for this job please click the apply lin kin the top right hand corner
<br><br>";
echo "<font size=3 ><b>Company Name:</b> $field11<br>";
echo "<font size=3 ><b>Contact Name:</b> $field6 $field7<br>";
echo "<font size=3 ><b>Email:</b><a href=mailto:field8>$field8</a><br>";
echo "<font size=3 ><b>Phone Number:</b>$field9<br>
";
// now $row_articles['MyDate'] will give the correct date
}
?>
<html>
<head>
<title>Add New MySQL User</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php include ("footer.php") ?>
-
Jun 24, 2007, 18:01 #4
You're using $result for both queries, corrupting it for the first one that way.
What even worse, you're executing the same query in the loop. Don't push your luck, the server might explode! (ok, a bit exaggerating, but that's a bad practice). Load the second query results into an array and then use it in the loop. Although, I'm not sure why do you output the same dates for every job there.Saul
-
Jun 25, 2007, 11:00 #5
- Join Date
- Oct 2004
- Location
- uk
- Posts
- 853
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
could you point out which bit of code is wrong?
-
Jun 25, 2007, 11:07 #6Code php:
$result=@mysql_query($query); if(@mysql_num_rows($result) > 0) { while($row_articals=@mysql_fetch_array($result)) { echo $row_articals['MyDate'] . "<br>"; } }
Saul
-
Jun 25, 2007, 12:35 #7
- Join Date
- Oct 2004
- Location
- uk
- Posts
- 853
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
how should it be?
-
Jun 25, 2007, 14:50 #8Code php:
$result2=@mysql_query($query); if(@mysql_num_rows($result2) > 0) { while($row_articals=@mysql_fetch_array($result2)) { echo $row_articals['MyDate'] . "<br>"; } }
Although, that's terrible. I don't see why shouldn't you create that list of dates in advance, then just add that to your jobs list. The dates are the same all the time anyway:
Code php:$id = $_GET['id']; $query="select *, date_format(startdate,'%D %b %Y') as MyDate from jobs"; $result=@mysql_query($query); $dates=''; if(@mysql_num_rows($result) > 0) { while($row_articals=@mysql_fetch_array($result)) { $dates.=$row_articals['MyDate'] . "<br>"; } } $sql = " select * from jobs where id=$id"; $result = mysql_query ($sql); while ($row = mysql_fetch_array($result)) { $field1= $row["jobtitle"]; $field2= $row["jobdescription"]; $field3= $row["location"]; $field4= $row["category"]; $field5= $row["salary"]; $field6= $row["firstname"]; $field7= $row["surname"]; $field8= $row["email"]; $field9= $row["telephone"]; $field10= $row["jobstatus"]; $field11= $row["company"]; $field13= $row["applications"]; $field14= $row["sublocation"]; $field15= $row["id"]; echo "<title>$field1</title>"; echo "<table width=100%><tr><td valign=top><font size=4 ><b>$field1</b></center></td><td align=right>job id:<B>$field15</b></td></tr></table><bR>"; echo "<table width=100%><tr><td width=58% valign=top>$field2</td><Td align=right valign=top> <Table><tr><td><img src=http://www.notexperienced.co.uk/images/add.gif></td><td valign=top> - <a href=savejob.php?id=" . $id . ">Add to my jobs</a></td></tr> <Tr><td><img src=http://www.notexperienced.co.uk/images/mail.gif></td><Td><a href=tellafriend.php?id=" . $id . ">Send to a friend</a></td></tr> <Tr><td><img src=http://www.notexperienced.co.uk/images/print.gif onClick=window.print()></td><td>- <a href=>Print This Page</a></td></tr> <Tr><td><img src=http://www.notexperienced.co.uk/images/apply.gif></td><td> <a href=apply.php?id=" . $id . ">Apply for this job</a></td></tr></table><Br><Br>" echo "<font size=3 ><b>Category:</b> $field4<br>"; echo "<font size=3 ><b>Location:</b> $field14, $field3</b> <br><a href='http://maps.google.com/maps?f=q&hl=en&q=rm64px'>View Map</a><br>"; echo "<font size=3 ><b>Salary:</b> $field5</b><br>"; echo "<font size=3 ><b>Job Status:</b> $field10</b><br>"; echo "<font size=3 ><b>Applications:</b> $field13</b><br>"; echo "<font size=3 ><b>Date Added:</b>"; echo $dates; echo " </b><br> </td> </tr> </table> <br> <font size=4 ><b>Contact Details</b> <br> <font size=2>If you wish to apply for this job please click the apply lin kin the top right hand corner <br><br>"; echo "<font size=3 ><b>Company Name:</b> $field11<br>"; echo "<font size=3 ><b>Contact Name:</b> $field6 $field7<br>"; echo "<font size=3 ><b>Email:</b><a href=mailto:field8>$field8</a><br>"; echo "<font size=3 ><b>Phone Number:</b>$field9<br> "; }
Saul
Bookmarks