Jump to content

Query problem


shyish

Recommended Posts

Ok, I'll start with the basics.

The website is all dynamic, based from one page with javascript used to make the content pages slide in and out.

One such page on this is a portfolio page, on which there is an image slider.

Now then, for this to work, each image slider needs an individual ID etc.; Not a problem.

The problem is with the query for the arrays, The images that'll be used in the image slider.

Earlier I had it working fine, but this was with just one "page" for the portfolio, now I am adding more as it will need it in future, and it broke because of various things most of which I fixed (mainly forgetting to change the variables)

 

So anyway, it wasn't working because it was using the same variables in the two queries, so I changed them, and now the second query - the one for arrays - does not work at all.

So here is the array query

<?php
$gquery="SELECT * FROM images WHERE $id=siteid";
$gresult=mysql_query($gquery);
$gnum=mysql_numrows($gresult);
mysql_close();
$g=0;
while ($g < $gnum) {
$site=mysql_result($result,$g,"site");
$imageurl=mysql_result($result,$g,"imageurl");
?>	
	["images/sites/<?php echo $site?>/<?php echo $imageurl ?>", "", "", "The website homepage"]<?php if ($g < $gnum) echo , ?>
<?php
$g++;
}
?>

 

If that's not enough to guess, here is the full script

<!-- Database connect -->
<?php
$host="localhost";
$username="velociv4_root";
$password="deathy13";
$database="velociv4_char";
mysql_connect($host,$username,$password);
@mysql_select_db($database) or die( "Unable to select database"); ?>
<!-- Begin First Query -->
<?PHP
$query="SELECT * FROM portfolio ORDER BY id ASC";
$result=mysql_query($query);
$num=mysql_numrows($result);
$i=0;
while ($i < $num) {
$title=mysql_result($result,$i,"name");
$thearticle=mysql_result($result,$i,"info");
$id=mysql_result($result,$i,"id");
$image=mysql_result($result,$i,"imageurl");
?>
<div class="item-content">
<h1><?PHP echo $title ?> </h1><br /><br />
<script type="text/javascript">
var mygallery=new fadeSlideShow({
wrapperid: "fadeshow<?PHP echo $id?>", //ID of blank DIV on page to house Slideshow
dimensions: [550, 300], //width/height of gallery in pixels. Should reflect dimensions of largest image
imagearray: [
<!-- Begin Second Query -->
<?php
$gquery="SELECT * FROM images WHERE $id=siteid";
$gresult=mysql_query($gquery);
$gnum=mysql_numrows($gresult);
mysql_close();
$g=0;
while ($g < $gnum) {
$site=mysql_result($result,$g,"site");
$imageurl=mysql_result($result,$g,"imageurl");
?>	
	["images/sites/<?php echo $site?>/<?php echo $imageurl ?>", "", "", "The website homepage"]<?php if ($g < $gnum) echo , ?>
<?php
$g++;
}
?>
],
displaymode: {type:'manual', pause:3000, cycles:0, wraparound:true},
persist: false, //remember last viewed slide and recall within same session?
fadeduration: 300, //transition duration (milliseconds)
descreveal: "always",
togglerid: "fadeshow<?PHP echo $id?>toggler"
})


</script>

<div id="fadeshow<?PHP echo $id?>toggler" style="width:600px; text-align:center; margin:10px">

<table width="600" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><div align="left"><a href="#" class="prev"><img src="images/left.png" style="border-width:0" /></a></div></td>
    <td>  <div id="fadeshow<?PHP echo $id?>"></div> </td>
    <td><div align="right"><a href="#" class="next"><img src="images/right.png" style="border-width:0" /></a></div></td>
  </tr>
  <tr>
    <td colspan="3"><span class="status" style="margin:0 50px; font-weight:bold"></span></td>
    </tr>
</table>
</div>
<?PHP echo $thearticle?></div>
<?php
$i++;
}
?>

 

I look forward to hearing from you,

Many thanks, Robin N.

Link to comment
https://forums.phpfreaks.com/topic/196517-query-problem/
Share on other sites

mysql_numrows is not a function unless you created it. any calls to mysql_numrows should be changed to mysql_num_rows().

 

put this at the top of your file as well and it should give you some useful errors.

 

ini_set ("display_errors", "1");
error_reporting(E_ALL);

 

and change any of your query calls to

 

mysql_query($gquery) or die(mysql_error());

Link to comment
https://forums.phpfreaks.com/topic/196517-query-problem/#findComment-1031874
Share on other sites

<!-- Database connect -->
<?php
$host="localhost";
$username="velociv4_root";
$password="#";
$database="velociv4_char";
mysql_connect($host,$username,$password);
@mysql_select_db($database) or die( "Unable to select database"); 
$query="SELECT * FROM portfolio ORDER BY id ASC";
$result=mysql_query($query) or die(mysql_error());;
$num=mysql_num_rows($result);
$i=0;
while ($i < $num) {
$title=mysql_result($result,$i,"name");
$thearticle=mysql_result($result,$i,"info");
$id=mysql_result($result,$i,"id");
?>
<div class="item-content">
<h1><?PHP echo $title ?> </h1><br /><br />
<script type="text/javascript">
var mygallery=new fadeSlideShow({
wrapperid: "fadeshow<?PHP echo $id?>", //ID of blank DIV on page to house Slideshow
dimensions: [550, 300], //width/height of gallery in pixels. Should reflect dimensions of largest image
imagearray: [
<!-- Begin Second Query -->
<?php
$host="localhost";
$username="velociv4_root";
$password="#";
$database="velociv4_char";
mysql_connect($host,$username,$password);
@mysql_select_db($database) or die( "Unable to select database"); 
$query2="SELECT * FROM images WHERE siteid=$id ORDER BY id ASC";
$result2=mysql_query($query2) or die(mysql_error());
$num2=mysql_num_rows($result2) or die(mysql_error());
mysql_close();
$i2=0;
while ($i2 < $num2) {
$site=mysql_result($result2,$i2,"site");
$imageurl=mysql_result($result2,$i2,"imageurl");
?>	
	["images/sites/<?php echo $site?>/<?php echo $imageurl ?>", "", "", "The website homepage"],
<?php
$i2++;
}
?>
],
displaymode: {type:'manual', pause:3000, cycles:0, wraparound:true},
persist: false, //remember last viewed slide and recall within same session?
fadeduration: 300, //transition duration (milliseconds)
descreveal: "always",
togglerid: "fadeshow<?PHP echo $id?>toggler"
})


</script>

<div id="fadeshow<?PHP echo $id?>toggler" style="width:600px; text-align:center; margin:10px">

<table width="600" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><div align="left"><a href="#" class="prev"><img src="images/left.png" style="border-width:0" /></a></div></td>
    <td>  <div id="fadeshow<?PHP echo $id?>"></div> </td>
    <td><div align="right"><a href="#" class="next"><img src="images/right.png" style="border-width:0" /></a></div></td>
  </tr>
  <tr>
    <td colspan="3"><span class="status" style="margin:0 50px; font-weight:bold"></span></td>
    </tr>
</table>
</div>
<?PHP echo $thearticle?></div>
<?php
$i++;
}
?>

Link to comment
https://forums.phpfreaks.com/topic/196517-query-problem/#findComment-1031889
Share on other sites

Ok I think I've figured out the reason for the problem.

 

Each time the code for the Main container "page" is repeated, it is calling upon the same code for the image slider.

This means that each instance of $gquery is appearing 3 times, so only working on the first.

What I need is a way for each variable to have an idividual ID each time.

Link to comment
https://forums.phpfreaks.com/topic/196517-query-problem/#findComment-1031916
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.