Jump to content

need help: get also the deleted items!


jac.kock

Recommended Posts

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,

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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

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.