Jump to content

Recommended Posts

$table is set, otherwise the page wouldn't even load to being with.

 

$table contains a given table name delivered through GET. $table is used mainly to look inside the appropriate MySQL table but also in places where the table name is used for display on the website.

 

I know for a fact that the variable is set because the page loads the contents of the proper table. What it isn't doing is working within this variable.

 

For example, I have a MySQL table called animal hat contains information about given animals. Where animal = goat, I have a page detailing the goat.

 

The variable is set because I can load such a page, the page tells me that this is a goat but it isn't displaying the goat's image because it isn't working inside the img variable.

In the code that sets $img = "..." . $table . "...";, $table does not have a value. Pretty simple, yes?

 

If you want someone in a forum to help you determine why that would be so, you must post your actual code (not just a couple of lines taken out of context.) Telling us about what your code is supposed to do is pointless, because obviously it is not doing what you are stating.

$table is set, otherwise the page wouldn't even load to being with.

 

$table contains a given table name delivered through GET. $table is used mainly to look inside the appropriate MySQL table but also in places where the table name is used for display on the website.

 

I know for a fact that the variable is set because the page loads the contents of the proper table. What it isn't doing is working within this variable.

 

For example, I have a MySQL table called animal hat contains information about given animals. Where animal = goat, I have a page detailing the goat.

 

The variable is set because I can load such a page, the page tells me that this is a goat but it isn't displaying the goat's image because it isn't working inside the img variable.

You must be unsetting or clearing $table somewhere before it reaches $img, if it's even reaching $img at all.

 

If $table was set, and you're code executed exactly as you said it does, then you wouldn't have a problem, would you?  It's not as though you found a bug in the PHP framework.

 

With that said, you must post your relevant code.

Here's all the code I've got!

<?php
  if (isset($_GET['item'])) {
include("variables.php");

$sql = "SELECT * FROM (.$table LEFT JOIN animalThemes2 USING (Name)) LEFT JOIN animalMethods2 USING (Name) WHERE .$table.Name = '{$item}'";
    $result = mysql_query($sql);
    if ($result) {
      if (mysql_num_rows($result) > 0) {
        $row = mysql_fetch_assoc($result);
?>

<?php include("header2.php"); ?>

<div class="contentArea">
<?php include("breadcrumb.php"); ?>
<div class="post" id="post-<?php the_ID(); ?>">
	<div class="postHeader">
		<center><h2 class="postTitle"><span><?php echo $itemHeader; ?></span></h2></center>
		<div class="bottom"><div>
			<span class="postDate"></span>
			<?php if($arjunaOptions['postsShowAuthor']): ?>
			<span class="postAuthor"></span>
			<?php endif; ?>
			<span></span></a>
		</div></div>
	</div>

<div class="postMySQL">	

<?php include("dateFunction.php"); ?>

<?php include("googlecode.php"); ?>

<table width="99%">
<tr>
<th colspan="4"><h2>Stats</h2></th>
</tr>
<tr>
<td width="21%" rowspan="5"><img src="<?php echo "$img{$row['Photo']}"; ?>"></td>

 

All the includes have nothing to do with the variables, except for variables.php:

<?php
$table = $_GET['type'];
$item = $_GET['item'];
$img = 'http://www.cool.com/stuff/' . $table . '/';
$url1='http://www.cool.com/TEST/itemspec2.php?item=';
$url2='&type=';
$itemHeader = '<a href="' . $url1 . $item . $url2 . $table . '" title="Permalink to ' . $item . '">' . $item . '</a>';

 

As stated, everything loads fine, except the last line of code where $img is called. As you can see, $table is not being reset anywhere.

 

Where

<td width="21%" rowspan="5"><img src="<?php echo "$img{$row['Photo']}"; ?>"></td>

the output should be http://www.cool.com/stuff/tableName/photo.png but what I get is http://www.cool.com/stuff//photo.png

I fixed the problem:

$img = 'http://www.cool.com/stuff/'.$table.'/';

 

why that works and the below doesn't is beyond me! Just seems like suddenly it's okay.

 

$img = 'http://www.cool.com/stuff/' . $table . '/';

If that were the case, the rest of your code wouldn't work as your concatenation is the same throughout the script.

 

I know you think that was the issue, but there is something else that was happening here that was causing $table to not be set within $img.

 

Look at another variable you have:

 

$itemHeader = '<a href="' . $url1 . $item . $url2 . $table . '" title="Permalink to ' . $item . '">' . $item . '</a>';

 

According to your "fix", that variable should not set either due to the spacing in your concatenation.

Look at another variable you have:

 

$itemHeader = '<a href="' . $url1 . $item . $url2 . $table . '" title="Permalink to ' . $item . '">' . $item . '</a>';

 

According to your "fix", that variable should not set either due to the spacing in your concatenation.

 

It shouldn't have, but it did. That's why i wasn't understanding why it wasn't working. I haven't changed any of my code and the other variables do not interfere. I still don't know why, but the code works now.

It shouldn't have, but it did. That's why i wasn't understanding why it wasn't working. I haven't changed any of my code and the other variables do not interfere. I still don't know why, but the code works now.

 

Again, have you attempted to echo the non-'fixed' $img?  Have you turned on error reporting?

 

Your code still has an error in it.  Getting expected, 'correct' results does not mean that your code is actually written correctly.  As others have said, PHP ignores white space.  There's a good chance that, despite expected output being seen, this error/bug will pop up again under a different set of circumstances.  You're better off debugging it properly than merely believing your impossible and meaningless fix worked and moving on.

Error reporting is turned on. There were no errors reporting at the time. I cannot seem to replicate the same errors with the non-fixed code; in other words, the non-fixed code also seems to work now. Unless the cache wasn't being refreshed in my browser while I was testing the code (which in itself is odd), I can't find an explanation for my results.

 

Believe me, if I could find the bug I would eliminate it but all signs are pointing to this not being a bug at all.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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