...

View Full Version : Whiles not working!



the-dream
06-03-2007, 06:56 PM
The whiles are not outputing any data and i have the data in my MySQL DB! Please take a look! Oh, and i have error reporting on!


<?php
$dizzle = $_GET['q'];
$connect = @mysql_connect("localhost","root","root") or die("Could not connect to database!");
$db = @mysql_select_db("sptxbx");
$query = 'SELECT * FROM `news` WHERE * LIKE \'%' . $dizzle . '%\'';
$mksql =@mysql_query($query);
$fet =@mysql_fetch_array($mksql);
?>

<?php
$dizzle1 = $_GET['q'];
$connect1 = @mysql_connect("localhost","root","root") or die("Could not connect to database!");
$db1 = @mysql_select_db("sptxbx");
$query1 = 'SELECT * FROM `games` WHERE * LIKE \'%' . $dizzle1 . '%\'';
$mksql1 =@mysql_query($query1);
$fet1 =@mysql_fetch_array($mksql1);
?>

<?php
$dizzle2 = $_GET['q'];
$connect2 = @mysql_connect("localhost","root","root") or die("Could not connect to database!");
$db2 = @mysql_select_db("sptxbx");
$query2 = 'SELECT * FROM `reviews` WHERE * LIKE \'%' . $dizzle2 . '%\'';
$mksql2 =@mysql_query($query2);
$fet2 =@mysql_fetch_array($mksql2);
?>

<div align="center">
<table width="410" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>News Results:</td>
</tr>
<?php while($fet =@mysql_fetch_array($mksql)) { ?>
<tr>
<td><a href="newsitem.php?id=<?php $fet['id']; ?>"><?php echo $fet['title']; ?></a></td>
</tr>
<?php } ?>
</table>
<br />
<table width="410" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Games Results:</td>
</tr>
<?php while($fet1 =@mysql_fetch_array($mksql1)) { ?>
<tr>
<td><a href="viewgame.php?id=<?php $fet1['id']; ?>"><?php echo $fet1['name']; ?></a></td>
</tr>
<?php } ?>
</table>
<br />
<table width="410" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Reviews Results:</td>
</tr>
<?php while($fet2 =@mysql_fetch_array($mksql2)) { ?>
<tr>
<td><a href="viewreview.php?id=<?php $fet2['id']; ?>"><?php echo $fet2['title']; ?></a></td>
</tr>
<?php } ?>
</table>
</div>

Fumigator
06-03-2007, 07:02 PM
Too bad you're not checking your queries for errors.... too bad.

the-dream
06-03-2007, 07:05 PM
oh yeah i still have the @ in there sorry for my mistake!!!

the-dream
06-03-2007, 07:07 PM
What could i use instead of mysql_fetch_array() could i use the mysql_querey() ?

the-dream
06-03-2007, 07:10 PM
or mysql_fetch_assoc() ?????

rafiki
06-03-2007, 07:13 PM
try it and see :)

mr e
06-03-2007, 07:16 PM
Take out all those @'s and you'll have a much easier time debugging

rafiki
06-03-2007, 07:18 PM
oh yeah i still have the @ in there sorry for my mistake!!!
i think he took them out already

the-dream
06-03-2007, 07:22 PM
i have tryed all of them but it come up with the same error:


Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /Applications/MAMP/htdocs/sptxbx_des/searchres.php on line 104


PLEASE GIVE ME SOME HELP!!!!!!!!!!!!!!!!!

the-dream
06-03-2007, 07:27 PM
Ok i have seen the error: 'SELECT * FROM `games` WHERE * LIKE \'%' . $dizzle1 . '%\'' to 'SELECT * FROM `games` WHERE name, des LIKE \'%' . $dizzle1 . '%\'' !!!


But i still get that not valid result resource!

mr e
06-03-2007, 07:27 PM
Try changing your queries to this and see if you're getting errors


mysql_query($query) OR die(mysql_error());

the-dream
06-03-2007, 07:30 PM
i cannot see my syntax error! I get this 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 ' des LIKE '%test%'' at line 1

the-dream
06-03-2007, 07:37 PM
done it!!!

Working Code:

<?php
$dizzle = $_GET['q'];
$connect = mysql_connect("localhost","root","root") or die("Could not connect to database!");
$db = mysql_select_db("sptxbx");
$query = 'SELECT * FROM `news` WHERE title LIKE \'%' . $dizzle . '%\'';
$mksql =mysql_query($query) or die(mysql_error()); ;
$fet =mysql_fetch_array($mksql);
?>

<?php
$dizzle1 = $_GET['q'];
$connect1 = mysql_connect("localhost","root","root") or die("Could not connect to database!");
$db1 = mysql_select_db("sptxbx");
$query1 = 'SELECT * FROM `games` WHERE name LIKE \'%' . $dizzle1 . '%\'';
$mksql1 =mysql_query($query1) or die(mysql_error()); ;
$fet1 =mysql_fetch_array($mksql1);
?>

<?php
$dizzle2 = $_GET['q'];
$connect2 = mysql_connect("localhost","root","root") or die("Could not connect to database!");
$db2 = mysql_select_db("sptxbx");
$query2 = 'SELECT * FROM `reviews` WHERE title LIKE \'%' . $dizzle2 . '%\'';
$mksql2 =mysql_query($query2) or die(mysql_error()); ;
$fet2 =mysql_fetch_array($mksql2);
?>

<div align="center">
<table width="410" border="0" cellspacing="0" cellpadding="5">
<tr>
<td bgcolor="#99CC00"><div align="center" class="style8 style7 style9">News Results:</div></td>
</tr>
<?php while($fet =mysql_fetch_array($mksql)) { ?>
<tr>
<td bgcolor="#CCCCCC"><a href="newsitem.php?id=<?php $fet['id']; ?>" class="style7"><?php echo $fet['title']; ?></a></td>
</tr>
<?php } ?>
</table>
<br />
<table width="410" border="0" cellspacing="0" cellpadding="5">
<tr>
<td bgcolor="#99CC00" class="style9"><div align="center" class="style8">Games Results:</div></td>
</tr>
<?php while($fet1 =mysql_fetch_array($mksql1)) { ?>
<tr>
<td bgcolor="#CCCCCC" class="style9"><a href="viewgame.php?id=<?php $fet1['id']; ?>" class="style7"><?php echo $fet1['name']; ?></a></td>
</tr>
<?php } ?>
</table>
<br />
<table width="410" border="0" cellspacing="0" cellpadding="5">
<tr>
<td bgcolor="#99CC00"><div align="center" class="style8">Reviews Results:</div></td>
</tr>
<?php while($fet2 =mysql_fetch_array($mksql2)) { ?>
<tr>
<td bgcolor="#CCCCCC"><a href="viewreview.php?id=<?php $fet2['id']; ?>" class="style7"><?php echo $fet2['title']; ?></a></td>
</tr>
<?php } ?>
</table>
</div>

<?php
mysql_free_result($mksql);
mysql_free_result($mksql1);
mysql_free_result($mksql2);
?>

mr e
06-03-2007, 07:40 PM
Good to hear

Just to let you know, you don't have to reconnect and reselect your database every time you want to query something (as long as you're using the same database), you can just connect once and select your database once, then query as many times as you'd like

bla
06-03-2007, 09:30 PM
try
<?
while($row = mysql_fetch_array($yourSqlQuery)) {
$id = $row["id"];
}
?>
Get rid of all your $fet variables this screwing up your php. this is created as a row automatically as above.

rafiki
06-03-2007, 09:33 PM
Good to hear

Just to let you know, you don't have to reconnect and reselect your database every time you want to query something (as long as you're using the same database), you can just connect once and select your database once, then query as many times as you'd like

or use mysql_pconnect



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum