FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Multiple <a> Tags, Filled With MySQL DB data with PHP
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Multiple <a> Tags, Filled With MySQL DB data with PHP [message #179220] Tue, 25 September 2012 17:43 Go to next message
tom.rankin51 is currently offline  tom.rankin51
Messages: 17
Registered: September 2012
Karma: 0
Junior Member
Hello

I am trying to create two image galleries using fancybox. There is no issue doing this by manually typing out a bunch of <a> tags with the info inside, but when I attempt to code a piece of PHP to pull this data from my database, it doesn't like it and displays the images strangely.

The "working" code is:

<a class="fancybox" rel="1" href="/image4.jpg" title="Title 1"><img src="thumbnail.jpg"></a>
<a class="fancybox" rel="1" href="/image3.jpg" title="Title 2"></a>
<a class="fancybox" rel="2" href="/image2.jpg" title="Title 3"><img src="thumbnail.jpg"></a>
<a class="fancybox" rel="2" href="/image1.jpg" title="Title 4"></a>

This essentially groups the images by the 'rel' tag automatically, showing two thumbnails which when clicked shows the corresponding images in descending order (ie last added).

In my database I have created a 'rel' field and populated it with either "1" or "2", and tried the following:

<!-- START OF PHP SCRIPT (DB OPEN)-->
<?
include("php/dbinfo.inc.php");

mysql_connect($hostname,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$visuals_query=mysql_query("SELECT id, imagelink, comment, picdate, rel FROM PictureMedia ORDER BY picdate DESC");

mysql_close();
?>
<!-- END OF PP SCRIPT (DB OPEN) -->

<?
while($r=mysql_fetch_assoc($visuals_query)) {
echo '<a class="fancybox" rel="'.$r["rel"].'" href="'.$r["imagelink"].'" title="'.$r["comment"].'"><img src="thumbnail.jpg"></a>';
}
?>

Now, I think that this should do exactly the same thing, other than showing four thumbnails obviously. What actually happens is that the first thumbnail loads the last added image in a new page, then the other three as expected but with the focus on the picture displayed by the query. It also did not show a Facebook share button when using PHP.

I understand that this issue isn't all down to PHP, but may be down to the fancybox script. However, I can't post in two groups simultaneously so if my code looks correct then I can go along another route.

Thanks in advance
Tom
Re: Multiple <a> Tags, Filled With MySQL DB data with PHP [message #179225 is a reply to message #179220] Tue, 25 September 2012 18:21 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 9/25/2012 1:43 PM, tom(dot)rankin51(at)googlemail(dot)com wrote:
> Hello
>
> I am trying to create two image galleries using fancybox. There is no issue doing this by manually typing out a bunch of <a> tags with the info inside, but when I attempt to code a piece of PHP to pull this data from my database, it doesn't like it and displays the images strangely.
>
> The "working" code is:
>
> <a class="fancybox" rel="1" href="/image4.jpg" title="Title 1"><img src="thumbnail.jpg"></a>
> <a class="fancybox" rel="1" href="/image3.jpg" title="Title 2"></a>
> <a class="fancybox" rel="2" href="/image2.jpg" title="Title 3"><img src="thumbnail.jpg"></a>
> <a class="fancybox" rel="2" href="/image1.jpg" title="Title 4"></a>
>
> This essentially groups the images by the 'rel' tag automatically, showing two thumbnails which when clicked shows the corresponding images in descending order (ie last added).
>
> In my database I have created a 'rel' field and populated it with either "1" or "2", and tried the following:
>
> <!-- START OF PHP SCRIPT (DB OPEN)-->
> <?
> include("php/dbinfo.inc.php");
>
> mysql_connect($hostname,$username,$password);
> @mysql_select_db($database) or die( "Unable to select database");
>
> $visuals_query=mysql_query("SELECT id, imagelink, comment, picdate, rel FROM PictureMedia ORDER BY picdate DESC");
>
> mysql_close();
> ?>
> <!-- END OF PP SCRIPT (DB OPEN) -->
>
> <?
> while($r=mysql_fetch_assoc($visuals_query)) {
> echo '<a class="fancybox" rel="'.$r["rel"].'" href="'.$r["imagelink"].'" title="'.$r["comment"].'"><img src="thumbnail.jpg"></a>';
> }
> ?>
>
> Now, I think that this should do exactly the same thing, other than showing four thumbnails obviously. What actually happens is that the first thumbnail loads the last added image in a new page, then the other three as expected but with the focus on the picture displayed by the query. It also did not show a Facebook share button when using PHP.
>
> I understand that this issue isn't all down to PHP, but may be down to the fancybox script. However, I can't post in two groups simultaneously so if my code looks correct then I can go along another route.
>
> Thanks in advance
> Tom
>

Look at the source code in your page - does it look correct?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Multiple <a> Tags, Filled With MySQL DB data with PHP [message #179228 is a reply to message #179225] Tue, 25 September 2012 18:26 Go to previous messageGo to next message
tom.rankin51 is currently offline  tom.rankin51
Messages: 17
Registered: September 2012
Karma: 0
Junior Member
I'm not sure what you mean. I think my source is correct yes, hence why I can't figure out the problem. As far as my knowledge extends, the php code I provided does exactly the same as the collection of <a> tags - but it produces completely different results.

I have already noted that my php code will produce four thumbnails which I have accounted for, however it i this code which will load the first image in a new page and not display facebook share links.

Tom

On Tuesday, September 25, 2012 7:21:50 PM UTC+1, Jerry Stuckle wrote:
> On 9/25/2012 1:43 PM, tom(dot)rankin51(at)googlemail(dot)com wrote:
>
>> Hello
>
>>
>
>> I am trying to create two image galleries using fancybox. There is no issue doing this by manually typing out a bunch of <a> tags with the info inside, but when I attempt to code a piece of PHP to pull this data from my database, it doesn't like it and displays the images strangely.
>
>>
>
>> The "working" code is:
>
>>
>
>> <a class="fancybox" rel="1" href="/image4.jpg" title="Title 1"><img src="thumbnail.jpg"></a>
>
>> <a class="fancybox" rel="1" href="/image3.jpg" title="Title 2"></a>
>
>> <a class="fancybox" rel="2" href="/image2.jpg" title="Title 3"><img src="thumbnail.jpg"></a>
>
>> <a class="fancybox" rel="2" href="/image1.jpg" title="Title 4"></a>
>
>>
>
>> This essentially groups the images by the 'rel' tag automatically, showing two thumbnails which when clicked shows the corresponding images in descending order (ie last added).
>
>>
>
>> In my database I have created a 'rel' field and populated it with either "1" or "2", and tried the following:
>
>>
>
>> <!-- START OF PHP SCRIPT (DB OPEN)-->
>
>> <?
>
>> include("php/dbinfo.inc.php");
>
>>
>
>> mysql_connect($hostname,$username,$password);
>
>> @mysql_select_db($database) or die( "Unable to select database");
>
>>
>
>> $visuals_query=mysql_query("SELECT id, imagelink, comment, picdate, rel FROM PictureMedia ORDER BY picdate DESC");
>
>>
>
>> mysql_close();
>
>> ?>
>
>> <!-- END OF PP SCRIPT (DB OPEN) -->
>
>>
>
>> <?
>
>> while($r=mysql_fetch_assoc($visuals_query)) {
>
>> echo '<a class="fancybox" rel="'.$r["rel"].'" href="'.$r["imagelink"].'" title="'.$r["comment"].'"><img src="thumbnail.jpg"></a>';
>
>> }
>
>> ?>
>
>>
>
>> Now, I think that this should do exactly the same thing, other than showing four thumbnails obviously. What actually happens is that the first thumbnail loads the last added image in a new page, then the other three as expected but with the focus on the picture displayed by the query. It also did not show a Facebook share button when using PHP.
>
>>
>
>> I understand that this issue isn't all down to PHP, but may be down to the fancybox script. However, I can't post in two groups simultaneously so if my code looks correct then I can go along another route.
>
>>
>
>> Thanks in advance
>
>> Tom
>
>>
>
>
>
> Look at the source code in your page - does it look correct?
>
>
>
> --
>
> ==================
>
> Remove the "x" from my email address
>
> Jerry Stuckle
>
> JDS Computer Training Corp.
>
> jstucklex(at)attglobal(dot)net
>
> ==================
Re: Multiple <a> Tags, Filled With MySQL DB data with PHP [message #179232 is a reply to message #179220] Tue, 25 September 2012 18:41 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
On Tue, 25 Sep 2012 10:43:45 -0700, tom.rankin51 wrote:

> I am trying to create two image galleries using fancybox. There is no
> issue doing this by manually typing out a bunch of <a> tags with the
> info inside, but when I attempt to code a piece of PHP to pull this data
> from my database, it doesn't like it and displays the images strangely.

Basic troubleshooting for php / mysql / html stuff:

1) Turn all the warnings on in php
2) Make sure that every database call tests for errors, and that they get
reported
2a) In extreme cases, output the actual sql query and var_dump the result:

I do something like this at the top of my code in such situations:

<?php

$debugtxt = "";
$debugging = false;
if ( $_SERVER['REMOTE_ADDR'] == $my_ip && $_GET['debug'] == "37" )
$debugging = true;

?>

and wrap something like this round every sql call:

<?php

$sql = ".......";

$result = mysqli->query( $sql );

$debugtxt .= "sql call to get date of last login from users table\n";
$debugtxt .= "sql: {$sql}\n";
$debugtxt .= "Result:" . var_dump( $result );

if ( $result === false ) {
...... do onething
}
else {
...... do otherthing
}

?>

When you generate the html, before the closing </body> tag:

<?php if ( $debugging ) echo "<hr><h1>Debugging</h1><pre>$debugtxt</pre>
\n"; ?>

3) check the server error logs after each request
4) view the html source of the pages you get so you can see the actual
html that your page is generating
5) When posting to the group, pare your code down to the minimum that
demonstrates the problem.

You will hopefully then be able to determine where your code is going
wrong and why.

In this particular case, I would suggest (4) is particularly important,
you have told us what you expect, and what code you use to generate it,
but have not shown us what the generated html looks like when examined
with the source viewer in your browser.

If no html is generated, go back to the server logs looking for a php
reported error. If your sql query is failing, your sql result set is
actually the value false, and you're failing to detect this. There may be
an sql error message in your server logs.

Rgds

Denis McMahon
Re: Multiple <a> Tags, Filled With MySQL DB data with PHP [message #179236 is a reply to message #179220] Tue, 25 September 2012 19:10 Go to previous messageGo to next message
tom.rankin51 is currently offline  tom.rankin51
Messages: 17
Registered: September 2012
Karma: 0
Junior Member
I'm way ahead of you. The code above is the minimum as far as I'm concerned - however, it's all for nothing when you consider that my error logs have absolutely nothing in them and the HTML code is exactly the same between my PHP and HTML.

This is why I'm reaching the end of my knowledge!

On Tuesday, September 25, 2012 6:43:45 PM UTC+1, (unknown) wrote:
> Hello
>
>
>
> I am trying to create two image galleries using fancybox. There is no issue doing this by manually typing out a bunch of <a> tags with the info inside, but when I attempt to code a piece of PHP to pull this data from my database, it doesn't like it and displays the images strangely.
>
>
>
> The "working" code is:
>
>
>
> <a class="fancybox" rel="1" href="/image4.jpg" title="Title 1"><img src="thumbnail.jpg"></a>
>
> <a class="fancybox" rel="1" href="/image3.jpg" title="Title 2"></a>
>
> <a class="fancybox" rel="2" href="/image2.jpg" title="Title 3"><img src="thumbnail.jpg"></a>
>
> <a class="fancybox" rel="2" href="/image1.jpg" title="Title 4"></a>
>
>
>
> This essentially groups the images by the 'rel' tag automatically, showing two thumbnails which when clicked shows the corresponding images in descending order (ie last added).
>
>
>
> In my database I have created a 'rel' field and populated it with either "1" or "2", and tried the following:
>
>
>
> <!-- START OF PHP SCRIPT (DB OPEN)-->
>
> <?
>
> include("php/dbinfo.inc.php");
>
>
>
> mysql_connect($hostname,$username,$password);
>
> @mysql_select_db($database) or die( "Unable to select database");
>
>
>
> $visuals_query=mysql_query("SELECT id, imagelink, comment, picdate, rel FROM PictureMedia ORDER BY picdate DESC");
>
>
>
> mysql_close();
>
> ?>
>
> <!-- END OF PP SCRIPT (DB OPEN) -->
>
>
>
> <?
>
> while($r=mysql_fetch_assoc($visuals_query)) {
>
> echo '<a class="fancybox" rel="'.$r["rel"].'" href="'.$r["imagelink"].'" title="'.$r["comment"].'"><img src="thumbnail.jpg"></a>';
>
> }
>
> ?>
>
>
>
> Now, I think that this should do exactly the same thing, other than showing four thumbnails obviously. What actually happens is that the first thumbnail loads the last added image in a new page, then the other three as expected but with the focus on the picture displayed by the query. It also did not show a Facebook share button when using PHP.
>
>
>
> I understand that this issue isn't all down to PHP, but may be down to the fancybox script. However, I can't post in two groups simultaneously so if my code looks correct then I can go along another route.
>
>
>
> Thanks in advance
>
> Tom
Re: Multiple <a> Tags, Filled With MySQL DB data with PHP [message #179237 is a reply to message #179232] Tue, 25 September 2012 19:16 Go to previous messageGo to next message
tom.rankin51 is currently offline  tom.rankin51
Messages: 17
Registered: September 2012
Karma: 0
Junior Member
I'm way ahead of you. My code is exactly the same regardless of whether I use the PHP or the HTML. My error logs contain absolutely nothing so it doesn't appear to be posting any errors at all.

I honestly thought the above was the bare minimum :-)

I'm pretty exasperated now though with it because it appears I've done everything right?
Tom

On Tuesday, September 25, 2012 7:41:38 PM UTC+1, Denis McMahon wrote:
> On Tue, 25 Sep 2012 10:43:45 -0700, tom.rankin51 wrote:
>
>
>
>> I am trying to create two image galleries using fancybox. There is no
>
>> issue doing this by manually typing out a bunch of <a> tags with the
>
>> info inside, but when I attempt to code a piece of PHP to pull this data
>
>> from my database, it doesn't like it and displays the images strangely.
>
>
>
> Basic troubleshooting for php / mysql / html stuff:
>
>
>
> 1) Turn all the warnings on in php
>
> 2) Make sure that every database call tests for errors, and that they get
>
> reported
>
> 2a) In extreme cases, output the actual sql query and var_dump the result:
>
>
>
> I do something like this at the top of my code in such situations:
>
>
>
> <?php
>
>
>
> $debugtxt = "";
>
> $debugging = false;
>
> if ( $_SERVER['REMOTE_ADDR'] == $my_ip && $_GET['debug'] == "37" )
>
> $debugging = true;
>
>
>
> ?>
>
>
>
> and wrap something like this round every sql call:
>
>
>
> <?php
>
>
>
> $sql = ".......";
>
>
>
> $result = mysqli->query( $sql );
>
>
>
> $debugtxt .= "sql call to get date of last login from users table\n";
>
> $debugtxt .= "sql: {$sql}\n";
>
> $debugtxt .= "Result:" . var_dump( $result );
>
>
>
> if ( $result === false ) {
>
> ..... do onething
>
> }
>
> else {
>
> ..... do otherthing
>
> }
>
>
>
> ?>
>
>
>
> When you generate the html, before the closing </body> tag:
>
>
>
> <?php if ( $debugging ) echo "<hr><h1>Debugging</h1><pre>$debugtxt</pre>
>
> \n"; ?>
>
>
>
> 3) check the server error logs after each request
>
> 4) view the html source of the pages you get so you can see the actual
>
> html that your page is generating
>
> 5) When posting to the group, pare your code down to the minimum that
>
> demonstrates the problem.
>
>
>
> You will hopefully then be able to determine where your code is going
>
> wrong and why.
>
>
>
> In this particular case, I would suggest (4) is particularly important,
>
> you have told us what you expect, and what code you use to generate it,
>
> but have not shown us what the generated html looks like when examined
>
> with the source viewer in your browser.
>
>
>
> If no html is generated, go back to the server logs looking for a php
>
> reported error. If your sql query is failing, your sql result set is
>
> actually the value false, and you're failing to detect this. There may be
>
> an sql error message in your server logs.
>
>
>
> Rgds
>
>
>
> Denis McMahon
Re: Multiple <a> Tags, Filled With MySQL DB data with PHP [message #179238 is a reply to message #179232] Tue, 25 September 2012 19:58 Go to previous messageGo to next message
tom.rankin51 is currently offline  tom.rankin51
Messages: 17
Registered: September 2012
Karma: 0
Junior Member
I'm not too sure how to debug correctly following these instructions. I can place the code at the beginning and end of my page, but I am getting a syntax error when typing $result = mysqli->query($sql);

Also, I'm unsure which bits I place around which other other bits :-D This is something which is taking me completely out of my depth to be honest so even though the description was in depth, it's maybe not as in depth enough for me.

Tom

On Tuesday, September 25, 2012 7:41:38 PM UTC+1, Denis McMahon wrote:
> On Tue, 25 Sep 2012 10:43:45 -0700, tom.rankin51 wrote:
>
>
>
>> I am trying to create two image galleries using fancybox. There is no
>
>> issue doing this by manually typing out a bunch of <a> tags with the
>
>> info inside, but when I attempt to code a piece of PHP to pull this data
>
>> from my database, it doesn't like it and displays the images strangely.
>
>
>
> Basic troubleshooting for php / mysql / html stuff:
>
>
>
> 1) Turn all the warnings on in php
>
> 2) Make sure that every database call tests for errors, and that they get
>
> reported
>
> 2a) In extreme cases, output the actual sql query and var_dump the result:
>
>
>
> I do something like this at the top of my code in such situations:
>
>
>
> <?php
>
>
>
> $debugtxt = "";
>
> $debugging = false;
>
> if ( $_SERVER['REMOTE_ADDR'] == $my_ip && $_GET['debug'] == "37" )
>
> $debugging = true;
>
>
>
> ?>
>
>
>
> and wrap something like this round every sql call:
>
>
>
> <?php
>
>
>
> $sql = ".......";
>
>
>
> $result = mysqli->query( $sql );
>
>
>
> $debugtxt .= "sql call to get date of last login from users table\n";
>
> $debugtxt .= "sql: {$sql}\n";
>
> $debugtxt .= "Result:" . var_dump( $result );
>
>
>
> if ( $result === false ) {
>
> ..... do onething
>
> }
>
> else {
>
> ..... do otherthing
>
> }
>
>
>
> ?>
>
>
>
> When you generate the html, before the closing </body> tag:
>
>
>
> <?php if ( $debugging ) echo "<hr><h1>Debugging</h1><pre>$debugtxt</pre>
>
> \n"; ?>
>
>
>
> 3) check the server error logs after each request
>
> 4) view the html source of the pages you get so you can see the actual
>
> html that your page is generating
>
> 5) When posting to the group, pare your code down to the minimum that
>
> demonstrates the problem.
>
>
>
> You will hopefully then be able to determine where your code is going
>
> wrong and why.
>
>
>
> In this particular case, I would suggest (4) is particularly important,
>
> you have told us what you expect, and what code you use to generate it,
>
> but have not shown us what the generated html looks like when examined
>
> with the source viewer in your browser.
>
>
>
> If no html is generated, go back to the server logs looking for a php
>
> reported error. If your sql query is failing, your sql result set is
>
> actually the value false, and you're failing to detect this. There may be
>
> an sql error message in your server logs.
>
>
>
> Rgds
>
>
>
> Denis McMahon
Re: Multiple <a> Tags, Filled With MySQL DB data with PHP [message #179239 is a reply to message #179228] Tue, 25 September 2012 20:02 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 9/25/2012 2:26 PM, tom(dot)rankin51(at)googlemail(dot)com wrote:
> On Tuesday, September 25, 2012 7:21:50 PM UTC+1, Jerry Stuckle wrote:
>> On 9/25/2012 1:43 PM, tom(dot)rankin51(at)googlemail(dot)com wrote:
>>
>>> Hello
>>
>>>
>>
>>> I am trying to create two image galleries using fancybox. There is no issue doing this by manually typing out a bunch of <a> tags with the info inside, but when I attempt to code a piece of PHP to pull this data from my database, it doesn't like it and displays the images strangely.
>>
>>>
>>
<snip code>
>>> Now, I think that this should do exactly the same thing, other than showing four thumbnails obviously. What actually happens is that the first thumbnail loads the last added image in a new page, then the other three as expected but with the focus on the picture displayed by the query. It also did not show a Facebook share button when using PHP.
>>
>>>
>>
>>> I understand that this issue isn't all down to PHP, but may be down to the fancybox script. However, I can't post in two groups simultaneously so if my code looks correct then I can go along another route.
>>
>>>
>>
>>> Thanks in advance
>>
>>> Tom
>>
>>>
>>
>>
>>
>> Look at the source code in your page - does it look correct?
>>
>>> I'm not sure what you mean. I think my source is correct yes, hence
why I can't figure out the problem. As far as my knowledge extends, the
php code I provided does exactly the same as the collection of <a> tags
- but it produces completely different results.
>
> I have already noted that my php code will produce four thumbnails
which I have accounted for, however it i this code which will load the
first image in a new page and not display facebook share links.
>
> Tom
>

(top posting fixed)

I mean look at the generated HTML - in your browser, "View Source".
Compare it to what works.

It obviously is NOT correct, or it would generate the desired results.

Also, you should NOT use the '@' character on your MySQL (or any other)
calls. It will hide any possible warning or error messages you get.

P.S. Please don't top post. Thanks.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Multiple <a> Tags, Filled With MySQL DB data with PHP [message #179241 is a reply to message #179238] Tue, 25 September 2012 20:12 Go to previous messageGo to next message
Luuk is currently offline  Luuk
Messages: 329
Registered: September 2010
Karma: 0
Senior Member
On 25-09-2012 21:58, tom(dot)rankin51(at)googlemail(dot)com wrote:
> I'm not too sure how to debug correctly following these instructions. I can place the code at the beginning and end of my page, but I am getting a syntax error when typing $result = mysqli->query($sql);
>
>> <?php
>> $sql = ".......";
>> $result = mysqli->query( $sql );

>> $debugtxt .= "sql: {$sql}\n";

or, that last one could be:
echo "SQL: {$sql}\n";

it should echo the query to the output......
Re: Multiple <a> Tags, Filled With MySQL DB data with PHP [message #179242 is a reply to message #179241] Tue, 25 September 2012 20:38 Go to previous messageGo to next message
tom.rankin51 is currently offline  tom.rankin51
Messages: 17
Registered: September 2012
Karma: 0
Junior Member
My HTML regardless of whether I use my PHP code or the <a> tags is exactly the same. I've checked this many times. I can't explain it any other way. It's definitely the same.

Also I'm not a PHP guru or anything - I have literally learnt what I thought I needed last weekend so I'm really new to all of this. I had a friend helping me oversee what I was doing, but like a good IT Support Tech he decided to not want to help me any more just as it was getting to the stuff that would need support.

So all of this above is going a bit over the top of my head.

On Tuesday, September 25, 2012 9:20:02 PM UTC+1, Luuk wrote:
> On 25-09-2012 21:58, tom(dot)rankin51(at)googlemail(dot)com wrote:
>
>> I'm not too sure how to debug correctly following these instructions. I can place the code at the beginning and end of my page, but I am getting a syntax error when typing $result = mysqli->query($sql);
>
>>
>
>>> <?php
>
>>> $sql = ".......";
>
>>> $result = mysqli->query( $sql );
>
>
>
>>> $debugtxt .= "sql: {$sql}\n";
>
>
>
> or, that last one could be:
>
> echo "SQL: {$sql}\n";
>
>
>
> it should echo the query to the output......
Re: Multiple <a> Tags, Filled With MySQL DB data with PHP [message #179243 is a reply to message #179242] Tue, 25 September 2012 20:53 Go to previous messageGo to next message
tom.rankin51 is currently offline  tom.rankin51
Messages: 17
Registered: September 2012
Karma: 0
Junior Member
Sorry I realised I top posted in that too after you said.

I'm such an idiot sometimes lol.
Re: Multiple <a> Tags, Filled With MySQL DB data with PHP [message #179244 is a reply to message #179220] Tue, 25 September 2012 22:27 Go to previous messageGo to next message
Christoph Becker is currently offline  Christoph Becker
Messages: 91
Registered: June 2012
Karma: 0
Member
tom.rankin51 wrote:
> Now, I think that this should do exactly the same thing, other than
> showing four thumbnails obviously. What actually happens is that the
> first thumbnail loads the last added image in a new page, then the
> other three as expected but with the focus on the picture displayed
> by the query. It also did not show a Facebook share button when
> using PHP.

Have you checked the JS (error) console of your browser? I would not be
surprised, if an error will be reported there.

--
Christoph M. Becker
Re: Multiple <a> Tags, Filled With MySQL DB data with PHP [message #179245 is a reply to message #179244] Tue, 25 September 2012 23:18 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 9/25/2012 6:27 PM, Christoph Becker wrote:
> tom.rankin51 wrote:
>> Now, I think that this should do exactly the same thing, other than
>> showing four thumbnails obviously. What actually happens is that the
>> first thumbnail loads the last added image in a new page, then the
>> other three as expected but with the focus on the picture displayed
>> by the query. It also did not show a Facebook share button when
>> using PHP.
>
> Have you checked the JS (error) console of your browser? I would not be
> surprised, if an error will be reported there.
>

What javascript is being used here?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Multiple <a> Tags, Filled With MySQL DB data with PHP [message #179246 is a reply to message #179241] Tue, 25 September 2012 23:19 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
On Tue, 25 Sep 2012 22:12:43 +0200, Luuk wrote:

> On 25-09-2012 21:58, tom(dot)rankin51(at)googlemail(dot)com wrote:
>> I'm not too sure how to debug correctly following these instructions.
>> I can place the code at the beginning and end of my page, but I am
>> getting a syntax error when typing $result = mysqli->query($sql);
>>
>>> <?php $sql = ".......";
>>> $result = mysqli->query( $sql );
>
>>> $debugtxt .= "sql: {$sql}\n";
>
> or, that last one could be:
> echo "SQL: {$sql}\n";
>
> it should echo the query to the output......

Yeah, but when I'm trying to debug code generating a web page, I stick
all the debugging output in a <pre> element at the end of the page, if I
don't get the pre element output the problem is invariably identified in
the server error log.

To the OP - sorry, you're not using mysqli .... replace "$result = mysqli-
> exec( $sql );" with whatever code you're using to make your database
call, maybe the "mysql_query" call.

Change this php:

$visuals_query=mysql_query("SELECT id, imagelink, comment, picdate, rel
FROM PictureMedia ORDER BY picdate DESC");

To:

<?php
$sql = "SELECT id, imagelink, comment, picdate, rel FROM PictureMedia
ORDER BY picdate DESC";
$visuals_query=mysql_query( $sql );
$debug = "sql: " $sql . "\nresult: " . var_dump( $visuals_query ) . "\n";
if ( $visuals_query == false )
$debug .= "sql error: " . mysql_error() . "\n";
?>

and then use the

<?php echo "<php>{$debug}</pre>"; ?>

to show the actual query, the query result set (warning, can be large)
and any sql error messages.

Rgds

Denis McMahon
Re: Multiple <a> Tags, Filled With MySQL DB data with PHP [message #179247 is a reply to message #179246] Tue, 25 September 2012 23:48 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 9/25/2012 7:19 PM, Denis McMahon wrote:
> On Tue, 25 Sep 2012 22:12:43 +0200, Luuk wrote:
>
>> On 25-09-2012 21:58, tom(dot)rankin51(at)googlemail(dot)com wrote:
>>> I'm not too sure how to debug correctly following these instructions.
>>> I can place the code at the beginning and end of my page, but I am
>>> getting a syntax error when typing $result = mysqli->query($sql);
>>>
>>>> <?php $sql = ".......";
>>>> $result = mysqli->query( $sql );
>>
>>>> $debugtxt .= "sql: {$sql}\n";
>>
>> or, that last one could be:
>> echo "SQL: {$sql}\n";
>>
>> it should echo the query to the output......
>
> Yeah, but when I'm trying to debug code generating a web page, I stick
> all the debugging output in a <pre> element at the end of the page, if I
> don't get the pre element output the problem is invariably identified in
> the server error log.
>
> To the OP - sorry, you're not using mysqli .... replace "$result = mysqli-
>> exec( $sql );" with whatever code you're using to make your database
> call, maybe the "mysql_query" call.
>
> Change this php:
>
> $visuals_query=mysql_query("SELECT id, imagelink, comment, picdate, rel
> FROM PictureMedia ORDER BY picdate DESC");
>
> To:
>
> <?php
> $sql = "SELECT id, imagelink, comment, picdate, rel FROM PictureMedia
> ORDER BY picdate DESC";
> $visuals_query=mysql_query( $sql );
> $debug = "sql: " $sql . "\nresult: " . var_dump( $visuals_query ) . "\n";
> if ( $visuals_query == false )
> $debug .= "sql error: " . mysql_error() . "\n";
> ?>
>
> and then use the
>
> <?php echo "<php>{$debug}</pre>"; ?>
>
> to show the actual query, the query result set (warning, can be large)
> and any sql error messages.
>
> Rgds
>
> Denis McMahon
>

Won't show much. The result of a mysql_query call is a result, not an
array. All it will say is "false" or "resource id 2" (or similar). And
your following "if" statement will handle the first result.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Multiple <a> Tags, Filled With MySQL DB data with PHP [message #179248 is a reply to message #179245] Wed, 26 September 2012 00:04 Go to previous messageGo to next message
Christoph Becker is currently offline  Christoph Becker
Messages: 91
Registered: June 2012
Karma: 0
Member
Jerry Stuckle wrote:
> What javascript is being used here?

Tom wants to present the images with Fancybox <http://fancybox.net/>
(see the OP). Since the generated (X)HTML is /reportedly/ the same as
the hand-written one, there /might/ be a problem on the javascript side
-- even if that's quite unlikely, if the generated code is /exactly/ the
same.

--
Christoph M. Becker
Re: Multiple <a> Tags, Filled With MySQL DB data with PHP [message #179249 is a reply to message #179248] Wed, 26 September 2012 01:45 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 9/25/2012 8:04 PM, Christoph Becker wrote:
> Jerry Stuckle wrote:
>> What javascript is being used here?
>
> Tom wants to present the images with Fancybox <http://fancybox.net/>
> (see the OP). Since the generated (X)HTML is /reportedly/ the same as
> the hand-written one, there /might/ be a problem on the javascript side
> -- even if that's quite unlikely, if the generated code is /exactly/ the
> same.
>

The HTML he's trying to emulate does not use javascript.

And even if it did - it would be the same javascript in both cases, and
would either work or fail in both cases.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Multiple <a> Tags, Filled With MySQL DB data with PHP [message #179250 is a reply to message #179249] Wed, 26 September 2012 06:16 Go to previous messageGo to next message
tom.rankin51 is currently offline  tom.rankin51
Messages: 17
Registered: September 2012
Karma: 0
Junior Member
So should I attempt debugging this? People seem tonhbe mixed opinions over whether it would be a wise thing to do?

There also seems to be debate over whether my HTML is the same in both cases. I can post this too ifnit helps?

I can post my JS but it is anything standard at fancyapps.com/fancybox
Re: Multiple <a> Tags, Filled With MySQL DB data with PHP [message #179252 is a reply to message #179250] Wed, 26 September 2012 08:39 Go to previous messageGo to next message
tom.rankin51 is currently offline  tom.rankin51
Messages: 17
Registered: September 2012
Karma: 0
Junior Member
To help things along, please find a test page at www.tomrankinmusic.com/vistest.php
Re: Multiple <a> Tags, Filled With MySQL DB data with PHP [message #179253 is a reply to message #179250] Wed, 26 September 2012 10:53 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 9/26/2012 2:16 AM, tom(dot)rankin51(at)googlemail(dot)com wrote:
> So should I attempt debugging this? People seem tonhbe mixed opinions over whether it would be a wise thing to do?
>

It's up to you. Do you want it to work?

> There also seems to be debate over whether my HTML is the same in both cases. I can post this too ifnit helps?
>

This is a PHP newsgroup, not an HTML newsgroup. You should be able to
compare your HTML with what works.

If it were the same in both cases, it would work the same in both cases.
It could be something as simple as a missing quote, unbalanced less
than/greater than signs, etc.

> I can post my JS but it is anything standard at fancyapps.com/fancybox
>

See above.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Multiple <a> Tags, Filled With MySQL DB data with PHP [message #179254 is a reply to message #179252] Wed, 26 September 2012 11:48 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 9/26/2012 4:39 AM, tom(dot)rankin51(at)googlemail(dot)com wrote:
> To help things along, please find a test page at www.tomrankinmusic.com/vistest.php
>

OK, so you're loading the same image 4 times in the first row, not 4
different images. Additionally, there is no facebook link in your code.

Looks to me the browser is doing exactly what the xhtml indicates.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Multiple <a> Tags, Filled With MySQL DB data with PHP [message #179256 is a reply to message #179252] Wed, 26 September 2012 12:12 Go to previous messageGo to next message
Christoph Becker is currently offline  Christoph Becker
Messages: 91
Registered: June 2012
Karma: 0
Member
tom.rankin51 wrote:
> To help things along, please find a test page at www.tomrankinmusic.com/vistest.php

The link is quite helpful. The second row works as expected according
to the generated XHTML (which BTW isn't valid; you should better fix
that, as it might cause problems with javascript). But the second
thumbnail is missing, what *might* be related to an error in your PHP code.

The first row seems to be a Fancybox related problem. So you might
better ask in an appropriate support forum/newsgroup. If I had to
*guess* what's causing the problem, I would say it's the numeric rel
attribute. You might try something like rel="gallery2" instead.

--
Christoph M. Becker
Re: Multiple <a> Tags, Filled With MySQL DB data with PHP [message #179257 is a reply to message #179249] Wed, 26 September 2012 12:16 Go to previous messageGo to next message
Captain Paralytic is currently offline  Captain Paralytic
Messages: 204
Registered: September 2010
Karma: 0
Senior Member
On Sep 26, 2:45 am, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> On 9/25/2012 8:04 PM, Christoph Becker wrote:
>
>> Jerry Stuckle wrote:
>>> What javascript is being used here?
>
>> Tom wants to present the images with Fancybox <http://fancybox.net/>
>> (see the OP).  Since the generated (X)HTML is /reportedly/ the same as
>> the hand-written one, there /might/ be a problem on the javascript side
>> -- even if that's quite unlikely, if the generated code is /exactly/ the
>> same.
>
> The HTML he's trying to emulate does not use javascript.
>
> And even if it did - it would be the same javascript in both cases, and
> would either work or fail in both cases.

The HTML he is trying to emulate is "input" to the fancybox
javascript. The class and rel attributes are picked up by the fancybox
javascript.

However, as you say, if the HTML code produced by the php was (as the
OP has said) EXACTLY the same as the hand written stuff then, since
the browser knows nothing about anything apart from the HTML, CSS &
Javascript, it would either work in both the "hand crafted" and the
"php generated" cases or it would not work in both.

Since the OP "says" that the HTML source is exactly the same in both
cases, yet it works with the hand crafted one but not in the php
generated one, we have to assume that he is either lying, or he has
not examined the two sets of HTML code accurately.
Re: Multiple <a> Tags, Filled With MySQL DB data with PHP [message #179259 is a reply to message #179247] Wed, 26 September 2012 14:25 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
On Tue, 25 Sep 2012 19:48:35 -0400, Jerry Stuckle wrote:

>> <?php $sql = "SELECT id, imagelink, comment, picdate, rel FROM
>> PictureMedia ORDER BY picdate DESC";
>> $visuals_query=mysql_query( $sql );
>> $debug = "sql: " $sql . "\nresult: " . var_dump( $visuals_query ) .
>> "\n"; if ( $visuals_query == false )
>> $debug .= "sql error: " . mysql_error() . "\n";
>> ?>

> Won't show much. The result of a mysql_query call is a result, not an
> array. All it will say is "false" or "resource id 2" (or similar). And
> your following "if" statement will handle the first result.

Point taken, it probably needs to be more like:

<?php
$sql = "SELECT id, imagelink, comment, picdate, rel FROM PictureMedia
ORDER BY picdate DESC";
$visuals_query = mysql_query( $sql );
$debug = "sql: " $sql . "\n";
if ( $visuals_query == false ) {
$debug .= "sql error: " . mysql_error() . "\n";
}
else {
$debug .= "Result set contained " . mysql_num_rows( $visuals_query
) ." rows\n";
if ( mysql_num_rows( $visuals_query ) > 0 ) {
$debug .= "Rows:\n"
while ( $tmp = mysql_fetch_assoc( $visuals_query ) )
$debug .= var_dump( $tmp );
mysql_data_seek( $visuals_query, 0 );
}
}
?>

Rgds

Denis McMahon
Re: Multiple <a> Tags, Filled With MySQL DB data with PHP [message #179261 is a reply to message #179220] Wed, 26 September 2012 20:35 Go to previous message
tom.rankin51 is currently offline  tom.rankin51
Messages: 17
Registered: September 2012
Karma: 0
Junior Member
After a bit of fiddling, it appears as though something doesn't like a) thumbnails loading for every image as per the code I had written, b) other code referencing the same images at once, c) even code nested in comment tags which I can't understand but it did seem to make a difference.

A fancybox gallery is so due to the contents of the "rel" tag, and then is displayed on the page by one initial <img> tag (obviously within the first <a> tag) for every instance of "rel".

Anyway, seeing as I have figured that bit out, I'm thinking I now need a bit of php to figure out how to load a thumbnail for the last added image only while keeping the <img> tags out of the loop for everything else. The kicker is that I would need the last added image for every different "rel" designation which will obviously be different.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Dynamic Links (MySQL/PHP)
Next Topic: Advice for Literature on PHP-Based Web Development Business Models
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 30 21:16:45 GMT 2024

Total time taken to generate the page: 0.02628 seconds