Jump to content





Recent Status Updates

  • Photo
      16 Apr
    Kadence

    If you're reading this, you're on my profile and I know you're on my profile because I'm probably viewing yours.

    Show comments (6)
  • Photo
      10 Apr
    Poe

    Finally (and hopefully) i'm getting a team together that knows a little of this and a little of that; and maybe all my open source projects that are half written can begin to be released. :)

View All Updates
Photo
- - - - -

Problem with echoing variable

echo


This topic has been archived. This means that you cannot reply to this topic.
26 replies to this topic

#1 Korlando

Korlando

    CC Regular

  • Member
  • PipPipPip
  • 43 posts

Posted 23 February 2013 - 03:40 PM

Even if my mind is going to blow...this code won't work :)

I have used the same code for a different website and it actually worked perfect. But this time I have an unexpected echo error.

I am trying to echo some "poems" that are saved to the database. And now I am trying to echo them. Here is the problem

 

I think this is the most importand part but if you want something more I can share it.

 

 

while($row = mysql_fetch_assoc($query)){
  $name = $row['name'];
  $epitheto = $row['ename'];
  $user = $row['username'];
  $category = $row['category'];
  $tsiattisto = $row['tsiattisto'];
?>
    <table width="200" border="0">
      <tr>
         <td><?php echo "$tsiattisto";
  }}else{
   echo "No result found";
}
}?></td>


 

 

   


Edited by Roger, 08 March 2013 - 03:12 PM.
Added code tags


#2 KodeKool

KodeKool

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 250 posts

Posted 23 February 2013 - 10:38 PM

are you running different Web server environments for the different sites? i.e apache on one, IIS on another?


~A program will always do what you tell it to do, and seldom what you want it to do~

Check out my latest PHP tutorial


#3 Korlando

Korlando

    CC Regular

  • Member
  • PipPipPip
  • 43 posts

Posted 24 February 2013 - 01:10 AM

both are working on 000webhost server.



#4 BlackRabbit

BlackRabbit

    CodeCall Legend

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 2,952 posts

Posted 24 February 2013 - 11:57 AM

What exactly is the error ?

 

I don't like the way you treat the tables and the php tags.

 

for example the echo, with else without the if in the visible block, that is not best code practice ...

 

and you are creating a new html table for every row ?

 

please copy a bigger piece of code, but I would start with re organizing the ideas there :D



#5 KodeKool

KodeKool

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 250 posts

Posted 24 February 2013 - 12:24 PM

from what i see in this code. your creating a new table for every iteration of the while loop, but not closing the previous td tag, try moving your <table> tag outside of the while loop and see if that changes anything


~A program will always do what you tell it to do, and seldom what you want it to do~

Check out my latest PHP tutorial


#6 Korlando

Korlando

    CC Regular

  • Member
  • PipPipPip
  • 43 posts

Posted 25 February 2013 - 11:16 AM

Kodekool I tried your suggest but I've got the same problem.
Black rabbit giving Almost the hole page code. I didn't include the database connection because it has been tested on other page(same project) and works fine
 

<?php
$i = 0;
$k = $_GET['c'];
$terms = explode(" " , $k );
$query = "SELECT * FROM tsiattista WHERE ";
foreach ($terms as $each){
$i++;
if($i == 1)
$query .= "category LIKE '%$each%'";
else
$query .= "OR category LIKE '%$each%'";
//connect database
////////
$query = mysql_query($query);
$numrows = mysql_num_rows($query);
if ($numrows > 0){
while($row = mysql_fetch_assoc($query)){
$name = $row['name'];
$epitheto = $row['ename'];
$user = $row['username'];
$category = $row['category'];
$tsiattisto = $row['tsiattisto'];
echo "$tsiattisto";
}}else{
echo "No result found";
}
}?>

 
I am not doing it on purpose but seriusly I can't put the code on code tags

Edited by BenW, 26 February 2013 - 04:09 PM.
Added code tags


#7 KodeKool

KodeKool

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 250 posts

Posted 25 February 2013 - 01:14 PM

when you run your code. what error are you getting?


~A program will always do what you tell it to do, and seldom what you want it to do~

Check out my latest PHP tutorial


#8 Korlando

Korlando

    CC Regular

  • Member
  • PipPipPip
  • 43 posts

Posted 26 February 2013 - 11:06 AM

 

when you run your code. what error are you getting?

I don't get error. I just can't see something printed on the page. I tested it with echoing a word. I can see the word but here I have a problem and I can't see the variable



#9 KodeKool

KodeKool

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 250 posts

Posted 26 February 2013 - 11:26 AM

do you have these two lines at the top of your code?

 

ini_set('display_errors','on');
error_reporting(E_ALL | E_STRICT);

 

this will turn on error reporting and display any errors that are occuring within your code. it could be a runtime error. try that and see if you get anything different.


~A program will always do what you tell it to do, and seldom what you want it to do~

Check out my latest PHP tutorial


#10 Korlando

Korlando

    CC Regular

  • Member
  • PipPipPip
  • 43 posts

Posted 01 March 2013 - 02:27 PM

Those two lines of code are very helpful! I found the true error.

 

Notice: Undefined index: name in /home/a3412571/public_html/tsiattistac.php on line 39

Notice: Undefined index: ename in /home/a3412571/public_html/tsiattistac.php on line 40

Notice: Undefined index: username in /home/a3412571/public_html/tsiattistac.php on line 41

Notice: Undefined index: category in /home/a3412571/public_html/tsiattistac.php on line 42

Notice: Undefined index: tsiattisto in /home/a3412571/public_html/tsiattistac.php on line 43

 

This means that the problem it's not the syntax but that my variables are not read



Now my problem it's new. 

Why this code is not working?

$terms = explode(" " , $k );
$query = "SELECT * FROM tsiattista WHERE ";
foreach ($terms as $each){
$i++;
if($i == 1)
$query .= "category LIKE '%$each%'";
else
$query .= "OR category LIKE '%$each%'";
//connect database
////////
$query = mysql_query($query);
$numrows = mysql_num_rows($query);


#11 Orjan

Orjan

    CC Mentor

  • Moderator
  • 2,910 posts

Posted 01 March 2013 - 03:15 PM

try echo your $query variable to see how it turned out before querying the database with it!


I'm a System developer at Redpill Linpro mainly working with SugarCRM.
Please DO NOT send mail or PM to me with programming questions, post them in the appropriate forum instead, where I and others can answer you.


#12 KodeKool

KodeKool

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 250 posts

Posted 01 March 2013 - 07:53 PM

Those two lines of code are very helpful! I found the true error.

 

Aren't they! :P ini_set has saved my life on multiple occasions. however it's more than worth noting that you should remove it once debugging is done and the code moves on to the production stage. just for clean up purposes mostly. but you don't want something to happen and users suddenly have information regarding bits and pieces of your code. that could lead to some problems. lol.

 

anyways, What's on line 39? would you mind including line numbers in your code inclusion? it would make things a lot easier to debug. however it might just be an error with PHP accessing the different returns from your $terms variable. it's a bit hard to tell considering we don't know what code is on line 39.


~A program will always do what you tell it to do, and seldom what you want it to do~

Check out my latest PHP tutorial