Jump to content

php option echo help


deant

Recommended Posts

Good day all,

 

I am really in need of some help here with my website. I am new to the php and mysql environs, but an avid supporter and learner.

 

I have a problem making my drop down 'category' option to work - as in when I select an option from the drop down list, it should pull the data from the mysql database which works magically with the keyword searches, etc...its just the category search not working - below is the coding which I am working with currently:

 

action=search.php method=get> Keyword : <input type=text name=k /> Category : <select name=b> <option value=0>All</option> <?php $connection = mysql_connect('127.0.0.1', 'vale_view', '8hw9er1' ); if (!$connection) {   die ("Could not connect to the database: <br />". mysql_error()); } $db_select=mysql_select_db('vale_view'); if (!$db_select) {   die ("Could not select the database: <br />". mysql_error()); } $query = "SELECT catid,catname FROM categories order by catname"; $result = mysql_query( $query ) or die('die'); if (!$result) {   die ("Could not query the database: <br />". mysql_error()); } while ($result_row = mysql_fetch_row($result)) { echo "<option value=".$result_row[0].">".$result_row[1]."</option>"; } mysql_close($connection); ?>

 

:confused:

 

Link to comment
Share on other sites

Tell me about it!!!!

 

Here

action=search.php method=get>
Keyword : <input type=text name=k />
Category :
<select name=b>
  <option value=0>All</option>
<?php
$connection = mysql_connect('127.0.0.1', 'vale_view', '[REMOVED]' );
if (!$connection) {
  die ("Could not connect to the database: <br />". mysql_error());
}
$db_select=mysql_select_db('vale_view');
if (!$db_select) {
  die ("Could not select the database: <br />". mysql_error());
}
$query= "SELECT catid,catname FROM categories order by catname";
$result = mysql_query( $query ) or die('die');
if (!$result) {
  die ("Could not query the database: <br />". mysql_error());
}

while ($result_row = mysql_fetch_row($result)) {
  echo "<option value=".$result_row[0].">".$result_row[1]."</option>";
}
mysql_close($connection);
?>
</select>

 

Also what you do mean by "not working" ?

Link to comment
Share on other sites

I appreciate the input, what I mean by not working is this:

 

On the web page itself, when I scroll onto the drop down menu list on 'categories' and then click on a category, thus displaying it in the box and then proceed to click on the 'search' button, it searches throughout the database (mysql), but wont give me the data which is listed under the category which I selected. It merely goes back to the first page of data pulled from the mysql database and thats it.

 

I did try the code given, but doesnt help, it only makes the whole page dissapear with nothing on, but an error message.

 

Any further suggestions?

 

With appreciation,

Dean

Link to comment
Share on other sites

Okay,

 

Thanks again for the quick feedback 'MadTechie'. I am glad to have this correspondence with you. It seems as though you get straight to the point and it's much appreciated.

 

If I could ask you to go onto the website and check out what I mean: www.vale-view.co.za/search. Once on there you can test the drop down 'category' option and select a category, then proceed to click on the 'search' button -  I'm sure you will get a better idea of what I am talking about and perhaps give a clearer perspective on this issue.

 

Again, many thanks for the input, its a bit frustrating as everything seems to be set up, but probably just needs some tweaks on the coding....I can't tell.

 

Kind Regards

 

Dean

Johannesburg

Link to comment
Share on other sites

The problem is, you have only posted the code that deals with the creating the Category drop down but what code run when you click search,

is it possible to post the whole page or at least the part that handles the GET/POST requests

 

Please make sure you put the code in-between code tags (click the # button)

 

Link to comment
Share on other sites

Good day 'MadTechie',

 

Thanks again. Below is the code involved for the category search. I think you are correct when you say that there is no GET / POST request for that, but only one for the keyword search, however I would like you to look at it in anycase just so every aspect is laid out.

 

<form action=search.php method=get> Keyword : <input type=text name=k /> Category : <select name=b> <option value=0>All</option> <?php $connection = mysql_connect('127.0.0.1', 'vale_view', '8hw9er1' ); if (!$connection) {   die ("Could not connect to the database: <br />". mysql_error()); } $db_select=mysql_select_db('vale_view'); if (!$db_select) {   die ("Could not select the database: <br />". mysql_error()); } $query = "SELECT catid,catname FROM categories order by catname"; $result = mysql_query( $query ) or die('die'); if (!$result) {   die ("Could not query the database: <br />". mysql_error()); } while ($result_row = mysql_fetch_row($result)) { echo "<option value=".$result_row[0].">".$result_row[1]."</option>"; } mysql_close($connection); ?> </select> Area : <select name=c> <option value=1>All</option> <option value=2>Bedfordview</option> <option value=3>Edenvale</option> </select> <input type=submit value='Search' /> </form> </td> </tr>

 

Regards

 

Dean

Link to comment
Share on other sites

Hi Madtechie,

 

Here is another line of coding falling beneath the coding which I sent previously on the same page. I'm not sure if this will be necessary to give you??

 

<?php $connection = mysql_connect('127.0.0.1', 'vale_view', '8hw9er1' ); if (!$connection) {   die ("Could not connect to the database: <br />". mysql_error()); } $db_select=mysql_select_db('vale_view'); if (!$db_select) {   die ("Could not select the database: <br />". mysql_error()); } if ($_GET['k']) { if ($_GET['b'] != '0') { if ($_GET['c'] != '1') { $query = "SELECT * FROM companies where compname like '%".$_GET['k']."%' and catid = ".$_GET['b']." and areaid = ".$_GET['c']." ORDER BY COMPNAME"; } else { $query = "SELECT * FROM companies where compname like '%".$_GET['k']."%' and catid = ".$_GET['b']." ORDER BY COMPNAME"; } } else { $query = "SELECT * FROM companies where compname like '%".$_GET['k']."%' ORDER BY COMPNAME"; } } else { $query = "SELECT * FROM companies ORDER BY COMPNAME LIMIT 20"; } $result = mysql_query( $query ) or die('die'); if (!$result) {   die ("Could not query the database: <br />". mysql_error()); } echo "<table border=0px width=100%>"; while ($result_row = mysql_fetch_row($result)) { echo "<tr><td>".$result_row[1]."</td><td>".$result_row[2]."</td><td>".$result_row[3]."</td></tr>"; }?></table><br/><br/></font> </td> </tr> <tr> <td colspan=5 align=center valign=top> <font face='Calibri' size=2>Vale-View © Copyright 2010</font> </td> </tr></table></center></body></html>

 

Regards

 

Dean

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.