Jump to content

[SOLVED] PHP / MYSQL with links?


summerpewp

Recommended Posts

I'm trying to create a nice help file but running into a few problems. I dont know how to assign a link to the end of my .php?subject=x

 

here is my code...

 

echo '<span class="subh3"><a href="?topicid='.$row["topicid"].'">'.$row['subject'].'</a></span><br />';

 

i want the link to go to ?topicid=account or setup etc.. all of which are distinguished in the mysql database...

 

Right now its coming up with the link ?topicid= and thats it... not going anywhere..

 

Hopefully this makes sense.

 

Thanks for any help.

Link to comment
https://forums.phpfreaks.com/topic/84965-solved-php-mysql-with-links/
Share on other sites

i had that before and still no go...

 

i essentially want it to load the info on the right of the links..

 

this code doesn't work for me either, and the row is not empty.

 

echo '<span class="subh3"><a href="index.php?topicid='.$row['topicid'].'">'.$row['subject'].'</a></span><br />';

sure:

 

<?php include('connection.php') ?>

<div class="helpmenu">
<?php 
$query = "SELECT DISTINCT topic FROM help";
$sql1 = mysql_query($query);
while($row = mysql_fetch_array($sql1)){ 
	echo'<h2 class="subh2">',$row[0],'</h2>';

$q2 = "SELECT DISTINCT subject FROM help WHERE topic='$row[0]'";
$rh2 = mysql_query($q2);

while ($row = mysql_fetch_array($rh2)){
	echo '<span class="subh3"><a href="index.php?topicid='.$row['topicid'].'">'.$row['subject'].'</a></span><br />';
		}}



?>
</div>
<div class="helptopic">
<?php 
$query2 = "SELECT * FROM help WHERE topicid = '%s'";
$sprintf = sprintf($query2,mysql_real_escape_string($_GET['topicid']));
$sql2 = mysql_query($sprintf);
while($row = mysql_fetch_array($sql2)){
echo'<div class="question">'.$row['question'].'</div><br />
<div class="answer">'.$row['answer'].'</div><br />';
}

?>
</div>




Try

<?php include('connection.php') ?>

<div class="helpmenu">
<?php 
$query = "SELECT DISTINCT topic FROM help";
$sql1 = mysql_query($query);
while($row = mysql_fetch_array($sql1)){ 
	echo'<h2 class="subh2">'.$row[0].'</h2>';

$q2 = "SELECT DISTINCT(topic, topicid) FROM help WHERE topic='{$row[0]}'";
$rh2 = mysql_query($q2);

while ($row = mysql_fetch_array($rh2)){
	echo '<span class="subh3"><a href="index.php?topicid='.$row['topicid'].'">'.$row['subject'].'</a></span><br />';
		}}



?>
</div>
<div class="helptopic">
<?php 
$query2 = "SELECT * FROM help WHERE topicid = '%s'";
$sprintf = sprintf($query2,mysql_real_escape_string($_GET['topicid']));
$sql2 = mysql_query($sprintf);
while($row = mysql_fetch_array($sql2)){
echo'<div class="question">'.$row['question'].'</div><br />
<div class="answer">'.$row['answer'].'</div><br />';
}

?>
</div>

Eh, oh well, worth a shot. Never worked with DISTINCT.

<?php include('connection.php') ?>

<div class="helpmenu">
<?php 
$query = "SELECT DISTINCT topic FROM help";
$sql1 = mysql_query($query);
while($row = mysql_fetch_array($sql1)){ 
	echo'<h2 class="subh2">'.$row[0].'</h2>';

$q2 = "SELECT DISTINCT topicid FROM help WHERE topic='{$row[0]}'";
$rh2 = mysql_query($q2);

while ($row = mysql_fetch_array($rh2)){
	echo '<span class="subh3"><a href="index.php?topicid='.$row['topicid'].'">'.$row['subject'].'</a></span><br />';
		}}



?>
</div>
<div class="helptopic">
<?php 
$query2 = "SELECT * FROM help WHERE topicid = '%s'";
$sprintf = sprintf($query2,mysql_real_escape_string($_GET['topicid']));
$sql2 = mysql_query($sprintf);
while($row = mysql_fetch_array($sql2)){
echo'<div class="question">'.$row['question'].'</div><br />
<div class="answer">'.$row['answer'].'</div><br />';
}

?>
</div>

Ah I see, what about this:

<?php include('connection.php') ?>

<div class="helpmenu">
<?php 
$query = "SELECT DISTINCT topic FROM help";
$sql1 = mysql_query($query);
while($row = mysql_fetch_array($sql1)){ 
	echo'<h2 class="subh2">'.$row[0].'</h2>';

$q2 = "SELECT DISTINCT(subject), topicid FROM help WHERE topic='{$row[0]}'";
$rh2 = mysql_query($q2);

while ($row = mysql_fetch_array($rh2)){
	echo '<span class="subh3"><a href="index.php?topicid='.$row['topicid'].'">'.$row['subject'].'</a></span><br />';
		}}



?>
</div>
<div class="helptopic">
<?php 
$query2 = "SELECT * FROM help WHERE topicid = '%s'";
$sprintf = sprintf($query2,mysql_real_escape_string($_GET['topicid']));
$sql2 = mysql_query($sprintf);
while($row = mysql_fetch_array($sql2)){
echo'<div class="question">'.$row['question'].'</div><br />
<div class="answer">'.$row['answer'].'</div><br />';
}

?>
</div>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.