jac.kock Posted February 24, 2013 Share Posted February 24, 2013 hi all, i have a headlights table where only the items that arrend deleted should be displayed, but it shows also the deleted items! i know that im doing something wrong but i can seem to figure out what my code : <?php if(file_exists("../../support/connect.dat")) // user,pass and database file { include("../../support/connect.dat"); // database connection file } //################ connect to database ############## $link=mysql_connect($host, $user, $pass) or die(mysql_error()); mysql_select_db($data); $sql="Select * from headlights where delete_tab='0'"; // get only the none deleted! $res1=mysql_query($sql); $row=mysql_num_rows($res1); $item=rand('1',$row); // have multiple rows so random because every time the same is boring $sql="Select * from headlights where krant_id='$item'"; // select the none deleted $res=mysql_query($sql); $resl=mysql_fetch_array($res); ?> <!-- show the selected one --> <table width="100%"> <tr> <td class="head-td" height="150px" valign="top" align="top"> <? echo $resl["krant_item"]; // show the none deleted item?> </td> </tr> </table> can someone say how to fix this ??? thnx, Quote Link to comment https://forums.phpfreaks.com/topic/274897-need-help-get-also-the-deleted-items/ Share on other sites More sharing options...
Jessica Posted February 24, 2013 Share Posted February 24, 2013 What? The first query you have should be all you need, you don't need that second one. You also need to then loop through them instead of just showing one. Quote Link to comment https://forums.phpfreaks.com/topic/274897-need-help-get-also-the-deleted-items/#findComment-1414718 Share on other sites More sharing options...
jac.kock Posted February 24, 2013 Author Share Posted February 24, 2013 hi jessica, i have tryed everything i could think off and i dont know anymore! gan you please show me how to solf this please?? thnx jessica Quote Link to comment https://forums.phpfreaks.com/topic/274897-need-help-get-also-the-deleted-items/#findComment-1414722 Share on other sites More sharing options...
Jessica Posted February 24, 2013 Share Posted February 24, 2013 I have no idea what your question is. Please try to use proper spelling and grammar, and clearly state the problem. What datatype is the deleted column? You shouldn't put numbers in quotes, especially in SQL. Quote Link to comment https://forums.phpfreaks.com/topic/274897-need-help-get-also-the-deleted-items/#findComment-1414723 Share on other sites More sharing options...
jac.kock Posted February 24, 2013 Author Share Posted February 24, 2013 type of delete_tab = int(1) so it state 1 or 0, 1 = deleted! i want to kown the proper code to solve this, sorry for my bad english please edit my code so it will work jessica!?? thnx Quote Link to comment https://forums.phpfreaks.com/topic/274897-need-help-get-also-the-deleted-items/#findComment-1414724 Share on other sites More sharing options...
jac.kock Posted February 24, 2013 Author Share Posted February 24, 2013 type of delete_tab = int(1) so it state 1 or 0, 1 = deleted! i want to kown the proper code to solve this, sorry for my bad english please edit my code so it will work jessica!?? thnx what i mean is i want to display 0ne and not all of the none deleted ones!!! thats why i use rnd how can i show only the selected one by rnd? Quote Link to comment https://forums.phpfreaks.com/topic/274897-need-help-get-also-the-deleted-items/#findComment-1414728 Share on other sites More sharing options...
Jessica Posted February 24, 2013 Share Posted February 24, 2013 You are getting the count of how many rows are not deleted, then picking a number at random from 1 to that count. That doesn't give you the ID of the non-deleted row, it gives you a number that is useless. You can either select one row and ORDER BY RAND() or you can select all the rows, put the ids in an array and use array_shuffle. Quote Link to comment https://forums.phpfreaks.com/topic/274897-need-help-get-also-the-deleted-items/#findComment-1414729 Share on other sites More sharing options...
jac.kock Posted February 24, 2013 Author Share Posted February 24, 2013 oke i get what you mean but i have no idea how to do this will you edit my code to what youre saying? thnx jessica! Quote Link to comment https://forums.phpfreaks.com/topic/274897-need-help-get-also-the-deleted-items/#findComment-1414732 Share on other sites More sharing options...
Jessica Posted February 24, 2013 Share Posted February 24, 2013 Sure, my hourly rate is $100 with a min of 5 hours. Quote Link to comment https://forums.phpfreaks.com/topic/274897-need-help-get-also-the-deleted-items/#findComment-1414735 Share on other sites More sharing options...
jac.kock Posted February 25, 2013 Author Share Posted February 25, 2013 like this jessica? <?php if(file_exists("../../support/connect.dat")) // user,pass and database file { include("../../support/connect.dat"); // database connection file } //################ connect to database ############## $link=mysql_connect($host, $user, $pass) or die(mysql_error()); mysql_select_db($data); $sql="Select * from headlights where delete_tab='0' ORDER BY RAND()"; // get only the none deleted! $res1=mysql_query($sql); $res=mysql_fetch_array($res1); ?> <!-- show the selected one --> <table width="100%"> <tr> <td class="head-td" height="150px" valign="top" align="top"> <? echo $res["krant_item"]; // show the none deleted item?> </td> </tr> </table> or is this the wrong way? thnx jassica Quote Link to comment https://forums.phpfreaks.com/topic/274897-need-help-get-also-the-deleted-items/#findComment-1414819 Share on other sites More sharing options...
Jessica Posted February 25, 2013 Share Posted February 25, 2013 Add a LIMIT 1 and it should be fine. Did it work? Quote Link to comment https://forums.phpfreaks.com/topic/274897-need-help-get-also-the-deleted-items/#findComment-1414820 Share on other sites More sharing options...
jac.kock Posted February 25, 2013 Author Share Posted February 25, 2013 yes it works fine jessica thnx a lot Quote Link to comment https://forums.phpfreaks.com/topic/274897-need-help-get-also-the-deleted-items/#findComment-1414829 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.