summerpewp Posted January 8, 2008 Share Posted January 8, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/84965-solved-php-mysql-with-links/ Share on other sites More sharing options...
pocobueno1388 Posted January 8, 2008 Share Posted January 8, 2008 You need to put the name of the script before the "?". Instead of ?topicid= It should be script.php?topicid= Also, you may want to verify that the variable $row['topicid'] isn't empty. Quote Link to comment https://forums.phpfreaks.com/topic/84965-solved-php-mysql-with-links/#findComment-433260 Share on other sites More sharing options...
summerpewp Posted January 8, 2008 Author Share Posted January 8, 2008 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 />'; Quote Link to comment https://forums.phpfreaks.com/topic/84965-solved-php-mysql-with-links/#findComment-433262 Share on other sites More sharing options...
pocobueno1388 Posted January 8, 2008 Share Posted January 8, 2008 What does the URL look like exactly when you click on it? If there is nothing after the topicid=...then that variable is empty. Quote Link to comment https://forums.phpfreaks.com/topic/84965-solved-php-mysql-with-links/#findComment-433264 Share on other sites More sharing options...
Ken2k7 Posted January 8, 2008 Share Posted January 8, 2008 echo '<span class="subh3"><a href="{$_SERVER['PHP_SELF']}?topicid='.$row['topicid'].'">'.$row['subject'].'</a></span><br />'; Quote Link to comment https://forums.phpfreaks.com/topic/84965-solved-php-mysql-with-links/#findComment-433265 Share on other sites More sharing options...
summerpewp Posted January 8, 2008 Author Share Posted January 8, 2008 That above "fix" has an error.. the link is empty... index.php?topicid= but when i do a manual link to that .. it works fine... so it can't be empty Quote Link to comment https://forums.phpfreaks.com/topic/84965-solved-php-mysql-with-links/#findComment-433266 Share on other sites More sharing options...
Ken2k7 Posted January 8, 2008 Share Posted January 8, 2008 Can you post more of you code? Quote Link to comment https://forums.phpfreaks.com/topic/84965-solved-php-mysql-with-links/#findComment-433268 Share on other sites More sharing options...
summerpewp Posted January 8, 2008 Author Share Posted January 8, 2008 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> Quote Link to comment https://forums.phpfreaks.com/topic/84965-solved-php-mysql-with-links/#findComment-433269 Share on other sites More sharing options...
pocobueno1388 Posted January 8, 2008 Share Posted January 8, 2008 You never select "topicid" from the database in your query...that might explain why it's empty. Quote Link to comment https://forums.phpfreaks.com/topic/84965-solved-php-mysql-with-links/#findComment-433271 Share on other sites More sharing options...
summerpewp Posted January 8, 2008 Author Share Posted January 8, 2008 how do i select it and have it do a distinct search as well? Quote Link to comment https://forums.phpfreaks.com/topic/84965-solved-php-mysql-with-links/#findComment-433272 Share on other sites More sharing options...
Ken2k7 Posted January 8, 2008 Share Posted January 8, 2008 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> Quote Link to comment https://forums.phpfreaks.com/topic/84965-solved-php-mysql-with-links/#findComment-433274 Share on other sites More sharing options...
summerpewp Posted January 8, 2008 Author Share Posted January 8, 2008 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in on line 21 dont know what the problem is... Quote Link to comment https://forums.phpfreaks.com/topic/84965-solved-php-mysql-with-links/#findComment-433275 Share on other sites More sharing options...
Ken2k7 Posted January 8, 2008 Share Posted January 8, 2008 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> Quote Link to comment https://forums.phpfreaks.com/topic/84965-solved-php-mysql-with-links/#findComment-433276 Share on other sites More sharing options...
summerpewp Posted January 8, 2008 Author Share Posted January 8, 2008 Well i dont want duplicated items from the database to be shown, so i have to do distinct in order to prevent that... I'm rather new to php / mysql which is my problem... Quote Link to comment https://forums.phpfreaks.com/topic/84965-solved-php-mysql-with-links/#findComment-433277 Share on other sites More sharing options...
Ken2k7 Posted January 8, 2008 Share Posted January 8, 2008 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> Quote Link to comment https://forums.phpfreaks.com/topic/84965-solved-php-mysql-with-links/#findComment-433278 Share on other sites More sharing options...
summerpewp Posted January 8, 2008 Author Share Posted January 8, 2008 Thanks!! That worked perfectly Quote Link to comment https://forums.phpfreaks.com/topic/84965-solved-php-mysql-with-links/#findComment-433280 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.