Forum Moderators: coopster

Message Too Old, No Replies

Why won't variable work in include?

variable works fine when data is represented without being a variable

         

mylungsarempty

3:16 pm on Nov 6, 2010 (gmt 0)

10+ Year Member



How come
<?php $countwhat = "name_of_table"; include('../count.php'); ?>


won't work when count.php is:

<?php

$con = mysql_connect("localhost","u_censored","p_censored");
if (!$con){
die('Could not connect: ' . mysql_error());
}

mysql_select_db("db_censored", $con);

$result = mysql_query("SELECT * FROM '?countwhat'");

if($row = mysql_fetch_array($result)){

$the_topic = $row['topic_id'];

$sql="SELECT * FROM '?countwhat'";

$count_result=mysql_query($sql);

$count=mysql_num_rows($count_result);

echo "" . $count . " post";

if ($count = '1'){
echo "s";
}

}

?>


assuming the variable is the name of an actual table, when it was working fine before I defined the variable outside of count.php?

It worked when I just inserted the table name instead of using a variable.

The error message I receive is:
    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /mnt/w0335/d14/s28/b030fb5b/www/littlerockmusicscene.com/count.php on line 12


Why isn't the variable being passed properly into the include file?

Thanks,

Kyle

mylungsarempty

3:44 pm on Nov 6, 2010 (gmt 0)

10+ Year Member



Hahah! I finally saw it! See if you can find it too :)

coopster

12:38 pm on Nov 7, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Find what?
'?findwhat'"

;)

Glad you got it sorted.