korbenmxli Posted May 11, 2011 Share Posted May 11, 2011 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; ?> Quote Link to comment https://forums.phpfreaks.com/topic/236128-php-links-from-list-menu-dont-work/ Share on other sites More sharing options...
requinix Posted May 11, 2011 Share Posted May 11, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/236128-php-links-from-list-menu-dont-work/#findComment-1214072 Share on other sites More sharing options...
korbenmxli Posted May 11, 2011 Author Share Posted May 11, 2011 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 .... ... Quote Link to comment https://forums.phpfreaks.com/topic/236128-php-links-from-list-menu-dont-work/#findComment-1214109 Share on other sites More sharing options...
requinix Posted May 11, 2011 Share Posted May 11, 2011 Well yeah it doesn't create a link. It creates a . If you want a link use an . Quote Link to comment https://forums.phpfreaks.com/topic/236128-php-links-from-list-menu-dont-work/#findComment-1214149 Share on other sites More sharing options...
spiderwell Posted May 11, 2011 Share Posted May 11, 2011 if you wanted to use the select. you would need an onclick/change(i'm not sure which) event to post the form, then the receiving page could take the selected option value to generate a redirect to that page. Quote Link to comment https://forums.phpfreaks.com/topic/236128-php-links-from-list-menu-dont-work/#findComment-1214154 Share on other sites More sharing options...
korbenmxli Posted May 11, 2011 Author Share Posted May 11, 2011 use an <a>. ?? where i must use that option... sorry im kinda ne to php Quote Link to comment https://forums.phpfreaks.com/topic/236128-php-links-from-list-menu-dont-work/#findComment-1214166 Share on other sites More sharing options...
spiderwell Posted May 11, 2011 Share Posted May 11, 2011 he was refering to a link, you write a link in html: <a href="page.php">page</a> . you can then use php to echo out that if you can't get the concepts of links and the difference with a select you might struggle Quote Link to comment https://forums.phpfreaks.com/topic/236128-php-links-from-list-menu-dont-work/#findComment-1214192 Share on other sites More sharing options...
socratesone Posted May 12, 2011 Share Posted May 12, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/236128-php-links-from-list-menu-dont-work/#findComment-1214205 Share on other sites More sharing options...
korbenmxli Posted May 13, 2011 Author Share Posted May 13, 2011 hey!! tnx.. the suggest from socrates was the solution... i cant believe i was not think in something so simple... tnx 4 everything guys Quote Link to comment https://forums.phpfreaks.com/topic/236128-php-links-from-list-menu-dont-work/#findComment-1215019 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.