Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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>";
    }
share|improve this question
Is column 'linklabel' of type pageID? – djot Feb 3 '12 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? – Sean Walsh Feb 3 '12 at 1:05
1  
Can you show an example of what is put into $match - an example of what is found? – Jonathan Leffler Feb 3 '12 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. – K_G Feb 3 '12 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. – K_G Feb 3 '12 at 1:20

2 Answers

up vote 2 down vote accepted

$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
share|improve this answer
How would I be able to pull the content from the column that is equal to $match then..? – K_G Feb 3 '12 at 1:22
$res[$match] or $content[$match] – djot Feb 3 '12 at 1:26
Thanks djot you did it! Simply answer as always. – K_G Feb 3 '12 at 1:35
Thanks. Next time try at least to var_dump() everything from the beginning to the end/error to debug a script yourself. – djot Feb 3 '12 at 1:49

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) 
share|improve this answer
Tried this, still getting Array in the results. No MYSQL error. – K_G Feb 3 '12 at 1:16
can u echo the query and show that query, so that i can review it ? – Khawer Zeshan Feb 3 '12 at 1:18
If I put an echo, and then exit after the query, I get the number 1 displayed... – K_G Feb 3 '12 at 1:21
did u tried running query directly on the database table ??? – Khawer Zeshan Feb 3 '12 at 1:22
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). – K_G Feb 3 '12 at 1:23
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.