hi,

i'm trying to output some results from a mysql query but i cant output 2 of the fields

when i echo the sql i get

SELECT * FROM sf_stories ORDER BY type desc

and the fields in my table are

id, mem_id, series, cert, type, notes

when i run the following function in a loop $cert and $type do not display anything, however $row['id'] and $title do.

<?php
function get_story_entires($row, $rows, $cur) {

	$get_entries_rtn = "";

	$title = $row['series'];
	$cert = $row['cert'];
$cert = format(1,0,1,1, $cert);
$type = format(1,0,1,1, $type);
		$type = $row['type'];
		$title = format(1,0,1,1, $title);


	$get_entries_rtn .= "<a href=\"?go=book&id=".$row['id']."\" class=\"bread\">".$title."</a>";
echo $cert." ".$type;
		if ($cur < $rows) {
			$get_entries_rtn .= "<br>";
		}

	return $get_entries_rtn;

}
?>

the only thing i can think of is that the field types are enum(cert field), and set(type field), however i have other tables which contain enums and sets.

so in the end the output is just

Series

please could someone give me some insight?

thanks, Jon

    what does format() do? try viewing just the raw results without any formatting at all:

    print_r($row);
    

      yeh i did that (print_r($row)) already to check what was being outputted and it contains cert and type....

      Array ( [0] => 3 [id] => 3 [1] => 1 [mem_id] => 1 [2] => Wish [series] => Wish [3] => U [cert] => U [4] => Romance [type] => Romance [5] => Just like to say that this fic has nothing to do with my other story ‘Only Human?’ except for the characters and a few references. What I’m saying is you don’t have to read ‘Only Human?’ to enjoy this fic. Have fun! [notes] => Just like to say that this fic has nothing to do with my other story ‘Only Human?’ except for the characters and a few references. What I’m saying is you don’t have to read ‘Only Human?’ to enjoy this fic. Have fun! )

      the function format does several things
      1. changes nl2br
      2. changes [url] tags
      3. changes : ) to emoticons
      4. removes/adds slashes.

        So appearently your format function is cracked. Can you paste it to eval? Or start testing yourself: check whether the variable that the function returns contains information?

        j.

          well i know it isnt the function because i only tried to adding the function to see if i could get any output

          but sure i'll paste it anyway.

          <?php
          function format($smilies, $urls, $slashes, $nltobr, $string) {
          
          if ($smilies == "1") {
          	$newline = str_replace(':)','<img src="/images/emoticons/smiley.gif" title=":)">',$string);
          	$newline = str_replace(':(','<img src="/images/emoticons/frown.gif" width="18" height="18" title=":(">',$newline);
          	$newline = str_replace(';)','<img src="/images/emoticons/wink.gif" width="18" height="18" title=";)">',$newline);
          	$newline = str_replace(':P','<img src="/images/emoticons/nerr.gif" width="18" height="18" title=":P">',$newline);
          	$newline = str_replace('(H)','<img src="/images/emoticons/cool.gif" width="18" height="18" title="(H)">',$newline);
          	$newline = str_replace(':@','<img src="/images/emoticons/mad.gif" width="18" height="18" title=":@">',$newline);
          	$newline = str_replace(':D','<img src="/images/emoticons/vhappy.gif" width="18" height="18" title=":D">',$newline);
          	$newline = str_replace(':S','<img src="/images/emoticons/wacko.gif" width="18" height="18" title=":S">',$newline);
          	$newline = str_replace(':p','<img src="/images/emoticons/nerr.gif" width="18" height="18" title=":P">',$newline);
          	$newline = str_replace('(h)','<img src="/images/emoticons/cool.gif" width="18" height="18" title="(h)">',$newline);
          	$newline = str_replace(':d','<img src="/images/emoticons/vhappy.gif" width="18" height="18" title=":d">',$newline);
          	$newline = str_replace(':s','<img src="/images/emoticons/wacko.gif" width="18" height="18" title=":s">',$newline);
          	$newline = str_replace('(/)','<img src="/images/emoticons/tp.GIF" width="18" height="18" title="(/)">',$newline);
          
          	$string = $newline;
          }
          
          if ($urls == "1") {
          
          	$pattern2 = '#\[url2\s*=\s*(\w+://[^\]]+)\](.+?)\[/url2]#';
          	$replacement2 = '<a href="\1" target="_BLANK" class=\"bread\">\2</a>';
          	$pattern = '#\[url\s*=\s*(\w+://[^\]]+)\](.+?)\[/url]#';
          	$replacement = '<a href="\1" class=\"bread\">\2</a>';
          	$pattern3 = "#\[email=(.*?)\](.*?)\[/email\]#si";
          	$replacement3 = "<A HREF=\"mailto:\\1\" class=\"bread\">\\2</A>";
          	$pattern4 = "#\[FONT=(.*?)\]#is"; 
          	$replacement4 = "<font face='$1'>";
          
          	$string = preg_replace($pattern,$replacement,$string);
          	$string = preg_replace($pattern2,$replacement2,$string);	
          	$string = preg_replace($pattern3, $replacement3, $string);
          	$string = preg_replace($pattern4, $replacement4, $string);		
          
          }
          
          if ($slashes == "1") {
          
          	$string = stripslashes($string);
          
          }
          else if ($slashes == "2") {
          
          	$string = addslashes($string);
          
          }
          
          if ($nltobr == "1") {
          
          	$string = nl2br($string);
          
          }
          
          return $string;
          
          }
          ?>
          

          anything else?

            I feel a bit sily here, but ehh.. In your function call to the format function..

            shouldn't

            $cert = format(1,0,1,1, $cert);
            $type = format(1,0,1,1, $type);
            $type = $row['type'];
            $title = format(1,0,1,1, $title);

            be

            $cert = format(1,0,1,1, $row['cert']);
            $type = format(1,0,1,1, $row['type']);
            $type = $row['type'];
            $title = format(1,0,1,1, $row['title']);

            ?

            Of do you grab them from hte $row before this?

            J.

              just above where you pulled that from, is where i pick them from the $row

                OK, am I glad I said it was silly!

                Have you tried running this outside the function, so just using all the commands within the loop?

                An other small thing is that you format type, and only after that you get it from $row. Will not give you big problems, but potentially unexpected output.

                Further.. If the variables are defined in $row, and not when you echo them.. Strange!

                Try echo-ing them individually, and maybe try:

                $cert = $row['cert'];
                echo $cert."<hr>";
                echo $row['cert'];

                to see where you lose the info

                J.

                  after trying to put the functions in a new page and see where i was going wrong i have found the problem

                  it seems in my loops i was calling to a function get_story_entries()

                  but this function already existed in my class, and the function i was editting was called get_story_entires()

                  I and R mixed up.

                  So i didnt know what the problem was till the first function was removed and i got an error saying it didnt exist.

                  Sorry to waste peoples time, simple mistake i guess 🙁

                  [Edit] Sorry i had to be reminded about the topic resoved link, i havent used the forum in a couple of month

                    OK, no problem. If the problem is solved, could you please mark the thread resolved? (See link at bottom of messages)

                      Write a Reply...