0

I apologize if my question does not make sense. As you can see from the code below, it scans the PHP files, grabs the text between {( )} and stores it into $match.

Now what I am trying to do here is do a query on a table that looks for the column $match where the pageid is equal to the pageid from the URL and where the field(s) are not empty. So far it is only returning Array in the text areas.

Am I setting up the code correctly or am I missing something simple? I know the scanning portion is working because if I echo match I get the text between the {( )} areas. It just isn't doing the query right for some reason. Or like I said I am missing something. Any help would be great. Please let me know if you need further information. (I am not getting any MySQL errors).

$fn = "../templates/".$templateid.".php";

$file = file_get_contents($fn);

preg_match_all("#\{\('(\w+)'\)}#", $file, $matches);   

foreach ($matches[1] as $match) 
    {
    $result = mysql_query("SELECT * FROM pages WHERE $match IS NOT NULL AND linklabel = '$pageID'") or die("Err: ".mysql_error());

    $res = mysql_fetch_array($result);
    $content = $res;
    echo " <div id='tabs-".$match."'>
           <textarea id='".$match."' name='content-".$match."' class='fieldsetstyle'>".$content."</textarea>
                     <script type='text/javascript'>
                     CKEDITOR.replace( '".$match."' );
                     </script>
           </div>";
    }
5
  • Is column 'linklabel' of type pageID? Commented Feb 3, 2012 at 1:00
  • So, you're not getting any results? If you run the query directly on MySQL (via command line or phpMyAdmin or whatever) do you get results? Commented Feb 3, 2012 at 1:05
  • 1
    Can you show an example of what is put into $match - an example of what is found? Commented Feb 3, 2012 at 1:09
  • If I put the static column name into the query I do get the results I want, but this is a function that needs to be dynamic. Commented Feb 3, 2012 at 1:17
  • For Jonathan, example: {(test)} on templates page, test is stored into $match. Query then searches table for test, and then should display the content in the column for the desired linklabel. Commented Feb 3, 2012 at 1:20

2 Answers 2

3

$res IS an array, so try to output the correct column, like

echo $res['linklabel'];

or try var_dump()

var_dump($res);


$content = $res; // Still, $content is an array, not text
Sign up to request clarification or add additional context in comments.

4 Comments

How would I be able to pull the content from the column that is equal to $match then..?
$res[$match] or $content[$match]
Thanks djot you did it! Simply answer as always.
Thanks. Next time try at least to var_dump() everything from the beginning to the end/error to debug a script yourself.
0

Try this

 $result = mysql_query("SELECT * FROM pages WHERE ".$match." IS NOT NULL AND linklabel = '".$pageID."'") or die("Err: ".mysql_error());

Try This Update

Replace this

 foreach ($matches[1] as $match) 

With this

foreach ($matches[1][1] as $match) 

4 Comments

Tried this, still getting Array in the results. No MYSQL error.
can u echo the query and show that query, so that i can review it ?
Yes, obviously I can't use a variable. So when I put in the column name directly, it does return the desired results (the content in the field).
Broke the tabs jquery UI I had set up. djot's answer worked. Thanks though!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.