Forum Moderators: coopster
case "site":
echo "<BR><BR>SUBMENU:";
$query = "select * FROM links WHERE name IS 'site' ORDER BY name";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{echo "<br />¦ <a href=\"{$row['url']}\">{$row['name']}</a> ¦";
}
break; Which doesn't seem to work. I want the PHP script to select the rows where the column 'name' contains 'site' (So that I can use a switch to show the right links for the right category).
First, I had this:
SELECT category, url, name FROM links Which, of course, selects all links currently in the database.
Can anyone help me with this? It's probably something simple which I've forgotten.
Thanks in advance,
Stefan.
SQL has a lot of String Comparison Functions to help you locate only the rows you want. The LIKE predicate is one of them.
$query = "SELECT * FROM links WHERE name LIKE '%site%' ORDER BY name";
Since you seem to be using MySQL:
[dev.mysql.com...]
<edit>Thanks Michal ;)
Mcibor, should the code be
mysql_fetch_assoc($result)
instead of what I have right now?
I have another problem right now though. On the main page where the content will go, I have the following code:
<?php if($page == "") { include "content/site/news.txt"; } else { include ($page.".txt"); }?>
However, when I include the PHP navigation, it interferes with the content part. When I click on a link, it shows the links it finds in the database, but since the URLs are like this:
http://localhost:85/layout/main2.php?page=content/site/news
The menu script causes the content to load the starting page (news.txt) instead of keeping the current content and just displaying the new links. The code of the navigation:
<?
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$dbname = 'site';
$connect = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);echo"MENU:<br /><b><a href=\"?menu=site\">Site</a><br /> <a href=\"?menu=information\">Information</a><br /> <a href=\"?menu=media\">Media</a><br /> <a href=\"?menu=fun\">Fun</a><br /> <a href=\"?menu=reviews\">Reviews</a><br /> <a href=\"?menu=cheats\">Cheats</a><br /> <a href=\"?menu=webmasters\">Webmasters</a><br /></b>";
function index()
{
}
$choice=$_GET['menu'];switch($choice)
{case "site":
echo "<BR><BR>SUBMENU:";
$query = "SELECT * FROM links WHERE category LIKE '%site%' ORDER BY name";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{echo "<br />¦ <a href=\"{$row['url']}\">{$row['name']}</a> ¦";
}
break;etc.etc.
default:
index();
}
?>
Do you know how I can let these two scripts work together, so it keeps the content and displays the menu instead of going to main.php?menu=site (so it keeps [localhost:85...] and still loads the menu somehow)? I can't seem to figure out how to do this since adding the menu part at the end of the URL results in a 404 error.
Thanks,
Stefan.