...

View Full Version : List everything that meets criteria



Deacon Frost
02-15-2008, 08:15 PM
Ok, I've selected the rows from my database, and assigned it to variables.

Now I need to list everything that falls under the "Where row=value" criteria. Basically a giant list of everything that is in it.

My problem understanding how it would work is, i don't see how the variables would change less i changed the extraction method...


I also need an advanced MySQL query, how would I set more than one criteria. Would it be like...

SELECT * FROM table WHERE row=value && row=value ?

And...

After all of the above, where I get everything..

How would I set it so it displays, for instance 30, random results that match the criteria?

Andrew Johnson
02-15-2008, 08:22 PM
Now I need to list everything that falls under the "Where row=value" criteria. Basically a giant list of everything that is in it.



<table border="0" cellpadding="3" cellspacing="0">
<tr>
<th>Col1</th>
<th>Col2</th>
<th>Col3</th>
</tr>
<?php

$query = mysql_query("SELECT * FROM table");
while ($results = mysql_fetch_array($query))
{
?>
<tr>
<td><?php echo $results["Col1"]; ?></td>
<td><?php echo $results["Col2"]; ?></td>
<td><?php echo $results["Col3"]; ?></td>
</tr>
<?php
}

?>



I also need an advanced MySQL query, how would I set more than one criteria.


SELECT * FROM table WHERE col='value' AND col2='value2'



How would I set it so it displays, for instance 30, random results that match the criteria?


SELECT * FROM table LIMIT 30

Unfortunately there is no random command for MySQL

Hopefully this helps, you'll need to change the names of everything though since you didn't post your schema...

Deacon Frost
02-15-2008, 08:26 PM
thanks! I'ma update right now to see if I can alter it correctly to get it to work.

Unfortunately, everything above is gonna be used on one page XD!

EDIT:

But wait, I need to display 30 of the results using variabls. saying col1, col2, and col3 will only display the same results...

like so:

http://downstage.tv/test.php

:S

Deacon Frost
02-16-2008, 08:22 AM
<?php
include("/home/stage/public_html/css/inc/theaterconn.php");

$sql = "SELECT id,filmid,name FROM theater WHERE status='2' LIMIT 2 ORDER BY id";
$result = mysql_query( $sql ) or die('mysql_error()' . 'Error: ' . mysql_errno() );
$row = mysql_fetch_assoc($result);
$num = mysql_num_rows($result);

$id = $row['id'];
$filmid = $row['filmid'];
$name = $row['name'];

?>



<table>
<tr>
<td>
<form action="theater.php" method="get">
<input type="hidden" name="id" value ="<? echo $id ?>">
<input type="image" src="http://images.stage6.com/video_images/<? echo $filmid ?>t.jpg" value="Submit" alt="Go to Theater">
<br />
<center><? echo $name ?></center>
<tr>
<td>
<input type="hidden" name="id" value ="<? echo $id ?>">
<input type="image" src="http://images.stage6.com/video_images/<? echo $filmid ?>t.jpg" value="Submit" alt="Go to Theater">
<br />
<center><? echo $name ?></center>
</form>
</tr>
</table>




mysql_error()Error: 1064




Basically... I need it to behave much like that of comments. It needs to show the data in a table listed by the ID number, displaying only those that meet the criteria of the SQL database, and I want it to display 30 of them.

EDIT: (if I take out the LIMIT 2, then it shows TWO of the same image w/ the same database data. Instead of retrieving the other row's data and putting it in there...)


After trying something else:



<?php
include("/home/stage/public_html/css/inc/theaterconn.php");

$sql = "SELECT id,filmid,name FROM theater WHERE status='2' ORDER BY id";
$result = mysql_query( $sql ) or die('mysql_error()' . 'Error: ' . mysql_errno() );

while($row = mysql_fetch_array($result));


$id = $row['id'];
$filmid = $row['filmid'];
$name = $row['name'];

{

echo "<table>";
echo "<tr>";
echo "<td>";
echo "<form action='theater.php' method='get'>";
echo "<input type='hidden' name='id' value=";
echo $id . ">";
echo "<input type='image' src='http://images.stage6.com/video_images/";
echo $filmid . "t.jpg' value='Submit' alt='Go to Theater'>";
echo "<center>";
echo $name . "</center>";
echo "</form>";
echo "</tr>";
echo "</table>";
}
?>



It kept some things, but some things didn't work, experimenting w/ that to see what I get... >.>


(It seems when I do this, it doesn't display the image =/.)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum