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
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 />';

Link to comment
Share on other sites

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>




Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.