View unanswered posts | View active topics It is currently Mon May 23, 2022 11:32 pm



Reply to topic  [ 1 post ] 
 How can we avoid repeating it. 
Author Message
Junior Member

Joined: Fri Oct 09, 2009 3:37 am
Posts: 1
Post How can we avoid repeating an id
helo

pleas help me.

i have some question about this code.

we have a program that it Make 4 Column and 10 row.(From the database as a random)

Field id from table ads Including 1 to 99 (no repeat)

but some of the data Entered repeated.

How can we avoid repeating it.

For example,

11-32-45-28
56-12-11-99
80-13-20-21
...

Number 11 is repeated

note:there isn't any repeated data in the Database( there is one id=11 in the Database)

i will be glad if you answer to me.

tanks.
[php]<?php
include("config.php");

mysql_connect($db_server, $db_username, $db_password);
mysql_select_db($db_name);

$query = "SELECT COUNT(ID) FROM ads ";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$adcnt = $row[0];

$query = "SELECT * FROM ads ";
$result = mysql_query($query);
$i = 1;
while (($row = mysql_fetch_array($result)))
{
$rows[$i] = $row;
$i++;
}

$ids_arr = null;

for ($i=1; $i<=10; $i++)
{
$ids = null;

for ($j=1; $j<=4; $j++)
{
$cellno = ($i-1)*4+$j;

srand((double)microtime()*1000000);
$adno = mt_rand(1, ($adcnt));
$ids[$j] = $rows[$adno]['ID'];
}

$ids_arr[$i] = $ids;
}
print( $ids_arr[1][1]);
print("-");
print( $ids_arr[1][2]);
print("-");
print( $ids_arr[1][3]);
print("-");
print( $ids_arr[1][4]);
echo("
");
print( $ids_arr[2][1]);
print("-");
print( $ids_arr[2][2]);
print("-");
print( $ids_arr[2][3]);
print("-");
print( $ids_arr[2][4]);
echo("
");
print( $ids_arr[3][1]);
print("-");
print( $ids_arr[3][2]);
print("-");
print( $ids_arr[3][3]);
print("-");
print( $ids_arr[3][4]);
echo("
");
print( $ids_arr[4][1]);
print("-");
print( $ids_arr[4][2]);
print("-");
print( $ids_arr[4][3]);
print("-");
print( $ids_arr[4][4]);
echo("
");
print( $ids_arr[5][1]);
print("-");
print( $ids_arr[5][2]);
print("-");
print( $ids_arr[5][3]);
print("-");
print( $ids_arr[5][4]);
echo("
");
print( $ids_arr[6][1]);
print("-");
print( $ids_arr[6][2]);
print("-");
print( $ids_arr[6][3]);
print("-");
print( $ids_arr[6][4]);


?>
[/php]


Sat Oct 10, 2009 12:39 am
Report this post
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 1 post ] 

Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.