-
thank you friends for help me to solve a part of my probs;
i got the solution....................
name age
-------------------
sam 22
john 32
peter 45
george 12 this is the DB table. table name is "TEST"
here is the code.
DB and PHP connection
-----------------------
<?php require('Connections/DB1.php'); ?>
<?php
mysql_select_db($database_DB1, DB1);
$query_Recordset1 = "SELECT * FROM test";
$Recordset1 = mysql_query($query_Recordset1, $DB1) or die(mysql_error());
$tot_Rec = mysql_num_rows($Recordset1);
?>
operation
---------
<?php
for($i=0;$i<$tot_Rec;$i++)
{
$row_Recordset1 = mysql_fetch_array($Recordset1);
$tot_Col = sizeof($row_Recordset1);
for ($j=0;$j<$tot_Col;$j++)
{
if($j=2){
echo $row_Recordset1[$j];
echo "<br>";
}
else { echo "bye <br>";}
}
}
?>
the output is:
sam
john
peter
george
22
32
45
12
but wht i want is not this.....
i want some thing different. here we can get data in order.
but i want to print randomly. for examle if we have M row N coll.
i want to display
(3rd row, 2nd coll) then (1st row, 4th coll)..............like this i want to acess data randamly. in diff palce of my out put page.
once again thank you friends for help me to solve a part of my probs;
please help me to solve this whole problem. thank you.
-
Code:
<p>
<?php
require('Connections/DB1.php');
mysql_select_db($database_DB1);
$rs = mysql_query('select * from test order by rand()') or die(mysql_error());
$alldata = array();
while($row = mysql_fetch_array($rs))
$alldata = array_merge($alldata, $row);
usort($alldata, create_function('$a,$b', 'return rand() - 0.5;'));
foreach($alldata as $x) {
?>
<?php echo $x; ?>
<?php } ?>
</p>
-
hi TWEY
you are helping lot. thank you your help.
i cant understand the code. please explzin it........
plzzzzzzzzzzzzzzzzzzzzzz
-
It gets all the data, puts it in a big array, randomises it, then spits it out.
If you have a lot of data, this will be horribly inefficient, since you'll need to store all the data in memory.
-
i got error
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '()' at line 1
-
Sorry, it's rand(), not random(). Edited.
-
anyway
i had done it in diff way. very very thank you TWYN
<?php require('Connections/DB.php'); ?>
<?php
mysql_select_db($database_DB, $DB);
$query_Recordset1 = "SELECT * FROM test";
$Recordset1 = mysql_query($query_Recordset1, $DB) or die(mysql_error());
$tot_Rec = mysql_num_rows($Recordset1);
?>
<?php
for($i=0;$i<$tot_Rec;$i++)
{
$row_Recordset1 = mysql_fetch_array($Recordset1);
$tot_Col = sizeof($row_Recordset1);
for ($j=0;$j<$tot_Col;$j++)
{
$out[$i][$j]=$row_Recordset1[$j];
}
}
?>
<?php echo $out[0][0]; ?> <br>
<?php echo $out[1][5]; ?> <br>
<?php echo $out[0][3]; ?> <br>
<?php echo $out[1][0]; ?>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
this is the full source code, in this code you can access any data anywhere....
thank you all for helped me...................
is it right TWYN?