Forum Moderators: coopster

Message Too Old, No Replies

What's wrong with my syntax?

a href line doesn't make the title linked

         

BadGoat

12:26 pm on Apr 4, 2005 (gmt 0)

10+ Year Member



Hi!

This line in particular:

echo '<td>'.$row['date_string'].'</td><td><a href="details.php?id='.$row['id'].'"</a>'.$row['diwtitle'],'</td><td>'.$row['id'].'</td>';

Is supposed to make the result a clickable link, but it does not.. What have I done wrong on this line?

All code on page:

[php]
<?PHP
$connect= mysql_connect("localhost","root")
or die("Could not connect to database in localhost!");
$result=mysql_select_db("testdiw")
or die("Could not select that database!");

$curdate = date("F j, Y");

$sqlquery = "SELECT id, diwtitle, date_string FROM mktime WHERE date_string >= CURDATE() ORDER BY date_string";

$queryresult = mysql_query($sqlquery) or die(" Could not execute mysql query!");
$row = mysql_fetch_row($queryresult);
$date_string = $row[0];
$diwtitle = $row[1];
$id = $row[2];

$tdcount = 1;
$numtd = 1; // number of cells per row
echo '<table border="0" width="" bgcolor="">
<tr>
<td colspan=3 bgcolor="#000080"><font face="Tahoma" size="5" color="white"> I-DEP - Current Depositions</font></td>
</tr>
<tr>
<td bgcolor="#ccccff" width=100><font face="Tahoma" size=2 color="black"><b> Date of Dep </b></font></td>
<td bgcolor="#ccccff" width=400><font face="Tahoma" size=2 color="black"><b> Title </b></font></td>
<td bgcolor="#ccccff" width=60><font face="Tahoma" size=2 color="black"><b> Dep ID </b></font></td>';
while($row = mysql_fetch_array($queryresult)) {
if ($tdcount == 1) echo "<tr>";
//echo "<td>",$row['date_string'],"</td><td>",$row['diwtitle'],"</td><td>",$row['id'],"</td>";
echo '<td>'.$row['date_string'].'</td><td><a href="details.php?id='.$row['id'].'"</a>'.$row['diwtitle'],'</td><td>'.$row['id'].'</td>';
if ($tdcount == $numtd) {
echo "</tr>";
$tdcount = 1;
} else {
$tdcount++;
}
}
// time to close up our table
if ($tdcount!= 1) {
while ($tdcount <= $numtd) {
echo "<td>&nbsp;</td>";
$tdcount++;
}
echo "</tr>";
}
echo "</table>";
?>[/php]

PCInk

12:30 pm on Apr 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Run it in the browser and go to view source to see what is printing.

The line you highlighted looks like you are printing:

<a href="details.php?id=1"</a>

Which is obviously incorrect syntax.

benihana

12:32 pm on Apr 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<a href="details.php?id='.$row['id'].'"</a>'.$row['diwtitle']

you havent closed the href, and have nothing between the <a></a>

<added> what pcink said :)</added>

BadGoat

12:38 pm on Apr 4, 2005 (gmt 0)

10+ Year Member



When I view the page source, the table cell reports back this:

<td><a href="details.php?id=39" ></a></td>
But it does not make the content pulled from the db for that cell clickable. I think the closing </a> is in the wrong position.. I think it should be after '.$row['diwtitle'],' but I am not sure how to move it, what with all the 's and "s :p I have been trying, all unsuccessful so far..

EDIT: I moved the closing </a> tag to this:

echo '<td>'.$row['date_string'].'</td><td><a href="details.php?id='.$row['id'].'" '.$row['diwtitle'],'</a></td><td>'.$row['id'].'</td>';

And now when I view the page source it looks like it should echo a clickable link, but in the browser, there is now nothing in the field to click.. All text is missing from that column.

killroy

1:19 pm on Apr 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You still didn't clsoe hte href, and in the first post you once used a comma instead of a dot.

let me try ;)

echo '<td>'.$row['date_string'].'</td><td><a href="details.php?id='.$row['id'].'" '.$row['diwtitle'],'</a></td><td>'.$row['id'].'</td>';

should be...


echo '<td>'
.$row['date_string']
.'</td><td><a href="details.php?id='
.$row['id']
.'">'
.$row['diwtitle']
.'</a></td><td>'
.$row['id']
.'</td>';

BTW, the comma worked instead of a dot because echo takes multiple parameters and printes them out after each other, so you can actually replace all dots with commas ;)

Regards,
SN

dmmh

1:21 pm on Apr 4, 2005 (gmt 0)

10+ Year Member



?>
<td><?php echo $row['date_string'];?></td>
<td><a href="details.php?id=<?php echo $row['id'];?>"><?php echo $row['diwtitle'];?></a></td>
<td><?php echo $row['id'];?></td>

personally I find it much easier to switch back and forth between HTML and PHP, simply bc its better readable imo

killroy

1:47 pm on Apr 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



More compact:

<td><?=$row['date_string']?></td>
<td><a href="details.php?id=<?=$row['id']?>"><?=$row['diwtitle']?></a></td>
<td><?=$row['id']?></td>

;)

SN

BadGoat

2:19 pm on Apr 4, 2005 (gmt 0)

10+ Year Member



Thank you both! That worked, links now appear!

So here's a follow-up noob question..

I have it set to go to details.php, which is where I want to be able to edit any of the variables I have set.. Is the proper way to do this, to have the fields displayed in text boxes, which can be changed?

MrSpeed

3:18 pm on Apr 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So here's a follow-up noob question..

Yeah. On details.php you will call the DB and fill in the values on a form so you can edit them. You will then post the form and do an update on the DB.

BadGoat

7:03 pm on Apr 4, 2005 (gmt 0)

10+ Year Member



Hi!

echo '<td>'.$row['date_string'].'</td><td><a href="details.php?id='.$row['id'].'"> '.$row['diwtitle'],'</a></td><td>'.$row['id'].'</td>';

details.php is where I will edit the variables if needed. I created a variables.php page but nothing is pulled. Currentl;y the query statement on details.php is $sqlquery = "SELECT * FROM mktime ";

Does the correct query also reference the id which I want the data for?

jatar_k

7:48 pm on Apr 4, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



is mktime the actual name of the table?

given that is a php function name that table name is a bad idea.

secondly, are you sure nothing is getting pulled or just nothing being displayed?

BadGoat

8:05 pm on Apr 4, 2005 (gmt 0)

10+ Year Member



yes, the table is named mktime,, named after an earlier project where I was trying tpo learn something. When I put the query into the mysql command line it does echo results, so maybe it is just that nothing is being displayed.. There is nothing sisplayed when I view the page source.

jatar_k

8:11 pm on Apr 4, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



well, you will need to figure out where it is dying then, as that is what it sounds like is happening.

start echo'ing vars and adding or die to your mysql_query calls and see how far it gets.