rwachowiak Posted February 28, 2008 Share Posted February 28, 2008 Ok, so ive got my page: <!--- INCLUDE THE HEADER --> <?php include("incs/inc_header.php"); ?> <!--- INCLUDE THE HEADER --> <?php include 'libs/dbopen.php'; $query = "SELECT * FROM files"; $result = mysql_query($query); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "File Name: <span class='titlebar2'><a href='indextest.php?id={$row['id']}'>{$row['Filename']}</a></span> <br>" . "Keywords: <span class='description'>{$row['Keyword1']}, {$row['Keyword2']}</span> <br>" . "Description: <span class='description'>{$row['Description']}</span> <br>" . "Date Added: <span class='description'>{$row['DateAdded']}</span> <br><br>"; } include 'libs/dbclose.php'; ?> <!--- INCLUDE THE RECENT DOCS --> <?php include("incs/inc_recent.php"); ?> <!--- INCLUDE THE RECENT DOCS --> <!--- INCLUDE THE NAVIGATION --> <?php include("incs/inc_nav.php"); ?> <!--- INCLUDE THE NAVIGATION --> <!--- INCLUDE THE WIDGETS --> <?php include("incs/inc_widgets.php"); ?> <!--- INCLUDE THE WIDGETS --> </body> </html> And what i want to do is, when someone clicks on certain links on the page, say, "Tax" "Audit" "Engagement" etc, that the page changes to: Index.php?=Tax, or the corresponding link etc. And when that happens, the query changes to reflect that variable, so it only pulls certain documents from the query that only pertain to the link that was clicked. Can someone point me in the direction of a good tutorial on how to teach me to do such things? Or give me some start off code? Thanks! Quote Link to comment Share on other sites More sharing options...
Neptunus Maris Posted February 28, 2008 Share Posted February 28, 2008 Try using $_GET[]; Like: index.php?file=Tax <--- "Tax" would be the value To grab: $file = $_GET[file]; $query = "SELECT * FROM files WHERE filename = '$file'"; Quote Link to comment Share on other sites More sharing options...
uniflare Posted February 28, 2008 Share Posted February 28, 2008 an added note to neptunus maris ' example, when using any $_GET/$_POST or even ANY data directly from a user, always use "mysql_escape_string()" before inserting it into the query (you must be connected to mysql for this function to work). eg: <?php // connect $Query = "SELECT * FROM `tablename` WHERE `username`='".mysql_escape_string($_GET['user'])."';"; $Results = mysql_query($Query); print_r($Results); ?> this code would grab user details depending on which user the client has specified; http://localhost/test.php?user=rwachowiak or http://localhost/test.php?user=uniflare hope this helps, Quote Link to comment Share on other sites More sharing options...
rwachowiak Posted February 28, 2008 Author Share Posted February 28, 2008 i forgot to note im SOMEWHAT of a php noob, i can customize code to my liking, but creating from scratch is tough. First, how can i make the links change the page to index.php?=pagelinkname Let me try that first Quote Link to comment Share on other sites More sharing options...
uniflare Posted February 28, 2008 Share Posted February 28, 2008 this is html, whereever your menu is just change the links inside. <!--- INCLUDE THE NAVIGATION --> <?php include("incs/inc_nav.php"); ?> <!--- INCLUDE THE NAVIGATION --> this is your menu/navigation, give us this file: incs/inc_nav.php it will be a lot harder to customize a script to do what you are wanting than to create a switch script just for this purpose. Quote Link to comment Share on other sites More sharing options...
rwachowiak Posted February 28, 2008 Author Share Posted February 28, 2008 this is html, whereever your menu is just change the links inside. <!--- INCLUDE THE NAVIGATION --> <?php include("incs/inc_nav.php"); ?> <!--- INCLUDE THE NAVIGATION --> this is your menu/navigation, give us this file: incs/inc_nav.php it will be a lot harder to customize a script to do what you are wanting than to create a switch script just for this purpose. yep ok here you go: <div class="titlebar">Browse by Category</div> <!-- Keep all menus within masterdiv--> <div id="masterdiv"> <div class="menutitle" onclick="SwitchMenu('sub1')"> <img src="media/navigation/tax.jpg" align="absmiddle" /> Tax</div> <span class="submenu" id="sub1"> - <a href="new.htm">Popular Tax Wesbites</a><br> - <a href="hot.htm">What's hot</a><br> - <a href="revised.htm">Revised Scripts</a><br> - <a href="morezone/">More Zone</a> </span> <div class="menutitle" onclick="SwitchMenu('sub2')"> <img src="media/navigation/audit.jpg" align="absmiddle" /> Audit</div> <span class="submenu" id="sub2"> - <a href="notice.htm">Usage Terms</a><br> - <a href="faqs.htm">DHTML FAQs</a><br> - <a href="help.htm">Scripts FAQs</a> </span> <div class="menutitle" onclick="SwitchMenu('sub3')"> <img src="media/navigation/humanresources.jpg" align="absmiddle" /> Human Resources</div> <span class="submenu" id="sub3"> - <a href="http://www.codingforums.com">Coding Forums</a><br> </span> <div class="menutitle" onclick="SwitchMenu('sub4')"> <img src="media/navigation/computer.jpg" align="absmiddle" /> Computer</div> <span class="submenu" id="sub4"> - <a href="http://www.javascriptkit.com">JavaScript Kit</a><br> - <a href="http://www.freewarejava.com">Freewarejava</a><br> - <a href="http://www.cooltext.com">Cool Text</a><br> - <a href="http://www.google.com">Google.com</a> </span> <div class="menutitle" onclick="SwitchMenu('sub5')"> <img src="media/navigation/engagement.jpg" align="absmiddle" /> Engagement</div> <span class="submenu" id="sub5"> - <a href="#">Known Engagement Issues</a><br> </span> <div class="menutitle" onclick="SwitchMenu('sub6')"> <img src="media/navigation/support.jpg" align="absmiddle" /> Support Numbers</div> <span class="submenu" id="sub6"> - <a href="http://www.codingforums.com">Coding Forums</a><br> </span> <div class="menutitle" onclick="SwitchMenu('sub7')"> <img src="media/navigation/paperless.jpg" align="absmiddle" /> Paperless Documents</div> <span class="submenu" id="sub7"> - <a href="http://www.codingforums.com">Coding Forums</a><br> </span> <div class="menutitle" onclick="SwitchMenu('sub8')"> <img src="media/navigation/misc.jpg" align="absmiddle" /> Miscellaneous</div> <span class="submenu" id="sub8"> - <a href="http://www.codingforums.com">Coding Forums</a><br> </span></div> </td> </tr> <tr> Now, i got the WHERE statement working, <?php include 'libs/dbopen.php'; $query = "SELECT * FROM files WHERE Keyword1 = 'Tax'"; $result = mysql_query($query); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "File Name: <span class='titlebar2'><a href='indextest.php?id={$row['id']}'>{$row['Filename']}</a></span> <br>" . "Keywords: <span class='description'>{$row['Keyword1']}, {$row['Keyword2']}</span> <br>" . "Description: <span class='description'>{$row['Description']}</span> <br>" . "Date Added: <span class='description'>{$row['DateAdded']}</span> <br><br>"; } include 'libs/dbclose.php'; ?> Its pulling the correct document, now what i want to do is change the WHERE Keyword1 = 'Tax'" to like, WHERE keyword1 = "index.php?=THISHERE" type thing if you know what i mean!? Quote Link to comment Share on other sites More sharing options...
uniflare Posted February 28, 2008 Share Posted February 28, 2008 ahhh ok very simple: <?php include 'libs/dbopen.php'; // this variable has an if statement built in. (If Key is not found, set keyword to tax, otherwise set to keyword given. $Keyword1 = (isset($_GET['Key']))? mysql_escape_string($_GET['Key']) : "Tax"; $query = "SELECT * FROM files WHERE Keyword1 = '$Keyword1'"; $result = mysql_query($query); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "File Name: <span class='titlebar2'><a href='indextest.php?id={$row['id']}'>{$row['Filename']}</a></span> <br>" . "Keywords: <span class='description'>{$row['Keyword1']}, {$row['Keyword2']}</span> <br>" . "Description: <span class='description'>{$row['Description']}</span> <br>" . "Date Added: <span class='description'>{$row['DateAdded']}</span> <br><br>"; } include 'libs/dbclose.php'; ?> you would then use something like: http://localhost/index.php?Key=Tax hope this helps, Quote Link to comment Share on other sites More sharing options...
rwachowiak Posted February 28, 2008 Author Share Posted February 28, 2008 ahhh ok very simple: you would then use something like: http://localhost/index.php?Key=Tax hope this helps, Omg, ok perfect, its doing it perfectly, now let me try and fix those nav links, give me a sec! Quote Link to comment Share on other sites More sharing options...
rwachowiak Posted February 28, 2008 Author Share Posted February 28, 2008 Ok! So i changed the links to: - <a href="index.php?Key=Audit">All Audit Documents</a><br> and when i click the link it changes it perfectly! Ok, so now, its working just the way i want, BUT! for each File, it can have 2 keywords, how can i change the query to be an OR, and say if Keyword1 or Keyword2 = Key?=THISHERE ?!?!? Thanks again you guys are great! Quote Link to comment Share on other sites More sharing options...
uniflare Posted February 28, 2008 Share Posted February 28, 2008 <?php include 'libs/dbopen.php'; // this variable has an if statement built in. (If Key is not found, set keyword to tax, otherwise set to keyword given. $Keyword1 = (isset($_GET['Key']))? mysql_escape_string($_GET['Key']) : "Tax"; $query = "SELECT * FROM files WHERE Keyword1 = '$Keyword1' OR Keyword2 = '$Keyword'1"; $result = mysql_query($query); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "File Name: <span class='titlebar2'><a href='indextest.php?id={$row['id']}'>{$row['Filename']}</a></span> <br>" . "Keywords: <span class='description'>{$row['Keyword1']}, {$row['Keyword2']}</span> <br>" . "Description: <span class='description'>{$row['Description']}</span> <br>" . "Date Added: <span class='description'>{$row['DateAdded']}</span> <br><br>"; } include 'libs/dbclose.php'; ?> or to have mulitple keywords in the url eg index.php?Key=blah&Key2=Blah then: <?php include 'libs/dbopen.php'; // this variable has an if statement built in. (If Key is not found, set keyword to tax, otherwise set to keyword given. $Keyword1 = (isset($_GET['Key']))? mysql_escape_string($_GET['Key']) : "Tax"; $Keyword2 = (isset($_GET['Key2']))? mysql_escape_string($_GET['Key2']) : "Tax"; $query = "SELECT * FROM files WHERE Keyword1 = '$Keyword1' OR Keyword2 = '$Keyword'2"; $result = mysql_query($query); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "File Name: <span class='titlebar2'><a href='indextest.php?id={$row['id']}'>{$row['Filename']}</a></span> <br>" . "Keywords: <span class='description'>{$row['Keyword1']}, {$row['Keyword2']}</span> <br>" . "Description: <span class='description'>{$row['Description']}</span> <br>" . "Date Added: <span class='description'>{$row['DateAdded']}</span> <br><br>"; } include 'libs/dbclose.php'; ?> hope this helps, Quote Link to comment Share on other sites More sharing options...
rwachowiak Posted February 28, 2008 Author Share Posted February 28, 2008 ok i tried the first one, and it doesnt pull any documents at all. i tried a OR like you did before and it didnt work, is that the correct syntax? PS. even when i dont have Key?=something it doesnt pull the Tax documents like it did before Ok nevermind, you had a mini-typo, Keyword2 = '$Keyword'1"; misplaced the ' its working great now, thanks a lot! Now, my next project is getting a search engine going, theres gotta be some tuts on that right? Quote Link to comment Share on other sites More sharing options...
uniflare Posted February 28, 2008 Share Posted February 28, 2008 try this: <?php include 'libs/dbopen.php'; // this variable has an if statement built in. (If Key is not found, set keyword to tax, otherwise set to keyword given. $Keyword1 = (isset($_GET['Key']))? mysql_escape_string($_GET['Key']) : "Tax"; $query = "SELECT * FROM files WHERE Keyword1 = '$Keyword1' OR Keyword2 = '$Keyword'1"; $result = mysql_query($query) or die("Mysql Query: ".$query."<br />".mysql_error(); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "File Name: <span class='titlebar2'><a href='indextest.php?id={$row['id']}'>{$row['Filename']}</a></span> <br>" . "Keywords: <span class='description'>{$row['Keyword1']}, {$row['Keyword2']}</span> <br>" . "Description: <span class='description'>{$row['Description']}</span> <br>" . "Date Added: <span class='description'>{$row['DateAdded']}</span> <br><br>"; } include 'libs/dbclose.php'; ?> Quote Link to comment Share on other sites More sharing options...
rwachowiak Posted February 28, 2008 Author Share Posted February 28, 2008 ok simple one, $query = "select * FROM files WHERE Filename OR Description LIKE \"%$trimmed%\" order by Filename"; // EDIT HERE and specify your table and field names for the SQL query I have 3 other fields i want to search, so i thought this would work: $query = "select * FROM files WHERE Filename OR Description OR Keyword1 OR Keyword2 OR DateAdded LIKE \"%$trimmed%\" order by Filename"; // EDIT HERE and specify your table and field names for the SQL query but it does not, whats the correct way to do that? Quote Link to comment Share on other sites More sharing options...
uniflare Posted February 29, 2008 Share Posted February 29, 2008 lol sry for the typo:P, glad you caught it im not very adept with sql but try this: (almost definetely an easier way but i dont know it... yet:P) $query = "select * FROM `files` WHERE `Filename` LIKE \"%$trimmed%\" OR `Description` LIKE \"%$trimmed%\" OR `Keyword1` LIKE \"%$trimmed%\" OR `Keyword2` LIKE \"%$trimmed%\" OR `DateAdded` LIKE \"%$trimmed%\" order by `Filename`"; // EDIT HERE and specify your table and field names for the SQL query i just added the value to each where key. very long query but should work. Quote Link to comment 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.