Jump to content


Photo

BARAND NEEDED -- Boss fails to understand situation, need temporary solution


  • Please log in to reply
2 replies to this topic

#1 MrRay

MrRay
  • Members
  • PipPip
  • Member
  • 10 posts
  • LocationOtis, MA

Posted 22 July 2006 - 06:36 PM

I have setup a static menu, which I want to pass a keyword to a php script that already exists. How would I approach this?


[pre]
<?php
require('top.inc');
require('menu2.inc');


echo "
<div id='main' class='hideMe'>
<span class='content_header'>TEST </span>
<div class='content_box'> \n";


mysql_connect('localhost', 'blah', 'blah');
mysql_select_db('dbname');

$sql = "SELECT (data, number)
        FROM items
        ORDER BY area, locname";
$res = @mysql_query($sql);
$count = 0;
while (list ($data, $n) = mysql_fetch_row($res)) {
    echo "<div class='item_box'>\n
          <div class='item_pic'><a href='$n\.htm'>\n<img class='noborder'  src='styles/Images/lo_res/$n\.jpg'/></a>\n
  <div class='item_content'>\n
                $data\n<br/>Item no\. upper($n)\n</div></div>";
    if (++$count % 4 == 0) {
        echo "\n</div>\n\n";
    }
}
echo "<br/></div></div>\n";
require('content.inc');
require('footer.inc');
?>[/pre]

this code was originally from barand when he helped me out a few weeks ago, but i modified it for my application on the site. I want this code to take what the user sends through the link and make it use this script on that specific data

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 22 July 2006 - 09:27 PM

Let's assume the script above is "script2.php" and you have "script1.php" containing your menu.

Something like this:
<FORM method='POST' action='script2.php'>

<select name="keyword">
  <option value="keyword1">keyword1</option>
  <option value="keyword2">keyword2</option>
  <option value="keyword3">keyword3</option>
</select>
<br>
<input type="submit" name="submit" value="Submit">

</FORM>

Let's further assume your items table has a column called "keyword_col".

Change this bit
mysql_connect('localhost', 'blah', 'blah');
mysql_select_db('dbname');

$sql = "SELECT (data, number)
        FROM items
        ORDER BY area, locname";

to

mysql_connect('localhost', 'blah', 'blah');
mysql_select_db('dbname');

$keyword = $_POST['keyword'];

$sql = "SELECT (data, number)
        FROM items
        WHERE keyword_col = '$keyword'
        ORDER BY area, locname";

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 MrRay

MrRay
  • Members
  • PipPip
  • Member
  • 10 posts
  • LocationOtis, MA

Posted 24 July 2006 - 02:09 PM

you're awesome. when this site gets all of its kinks out and hes happy with it I'm gonna show you it. i owe you one. theres been so much going on and stuff here it wouldve been a nightmare finding time to figure it out. if I can get some free time maybe I'll try to help you guys convert to smf to return the favor :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users