Jump to content

php links from list menu dont work


korbenmxli

Recommended Posts

hi every one

i want to make a list from my database and if user click on one item it open a link... its a list of models of products so if click in one link me to the page of its full description, my database has the fields: "modelo" (model), and "paginal" the link page i make this code.. works fine cause display all the catalog but when i click in an item dont do nothing... hes the code.. what im missing??

tnx in advance

 

 

    <?PHP

// Connect to MySQL Server

@mysql_connect('localhost','user','password') or DIE("Couldn't Connect to MySQL Database");

 

// Select Database

@mysql_select_db('zerocctv_almacen') or DIE("Couldn't Select Database");

$sql = "SELECT modelo, paginal,precio,foto FROM modelos";

$result=mysql_query($sql);

$row_array=mysql_fetch_row($result);

$string='<select name=selection><option value=>modelo</option>';

 

for ($i=0;$i < mysql_num_rows($result);$i++)

{

if ($row_array[0]=="")

{

$row_array=mysql_fetch_row($result);

}

else

{

$string .='<option value="'.$row_array[1].'">'.$row_array[0]."</option>";

$row_array=mysql_fetch_row($result);

}

}

$string .='</SELECT>';

//echo "</label>";

echo $string;

?>

Link to comment
https://forums.phpfreaks.com/topic/236128-php-links-from-list-menu-dont-work/
Share on other sites

Simply clicking an item won't do anything unless you have some JavaScript code to make that happen.

If that's what you're talking about then that's what your problem is.

 

Otherwise

1. What does "dont do nothing" mean?

2. What does it do?

3. What is it supposed to do?

it display all records in the database but dont link to the page associated to the record, example

record 1 in the database is

modelo                    paginal

SF-6032                6032.html

SF-6032IR              sfri.html

....

...

 

You have some options here.

 

1) Keep everything you have, but wrap it in a form and create a button, like this:

 

?>

<form action="" method="post">

<?php echo $string; ?>

<input type="submit" value="go" />

</form>

 

...and at the top of the page, add some logic to check the value, and, if present, forward off to the page

<?php

if(isset($_POST['selection']) && and !empty($_POST['selection'])}{
  
  header("Location: http://www.example.com/" . $_POST['selection']);

}

?>

 

....or....

 

2) You can create links instead of a select box

 

// get rid of this
// $string='<select name=selection><option value=>modelo</option>';

// change this:
// $string .='<option value="'.$row_array[1].'">'.$row_array[0]."</option>";

// to this:
$string .= '<a href="'.$row_array[1].'">'.$row_array[0]."</a><br />";
// (you can also change this to any kind of format or wrapper for the <a> tag, such as wrapping them in <li> elements

// get rid of this
$string .='</SELECT>';

 

Hope that helps.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.