SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2010
    Posts
    97
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    variables in a switch

    I'm trying to pull the meta data & page titles from my db, but the method below just throws an error. I'm wondering if I have messed up somehow putting a variable as a case in the switch statement?
    I just get this warning: <meta name="keywords" content="<br />
    <b>Warning</b>: sprintf() [<a href='function.sprintf'>function.sprintf</a>]: Too few arguments in <b>/home/test/public_html/testsite/functions.php</b> on line <b>163</b><br />
    <br />
    <b>Warning</b>: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in <b>/test/easmaweb/public_html/testsite/functions.php</b> on line <b>138</b><br />
    ">


    Here's my database table:


    Here's my code:
    PHP Code:


    // Turn a result into an assoc array
    function result_to_assoc($result)
        {
          
    $result_array = array();
            for (
    $i=0$row mysql_fetch_assoc($result) ; $i++)
            {
               
    $result_array[$i] = $row
            }
            
            return 
    $result_array;
        }

    // Output the page data
        
    function pages($name)
      {
          
    db_connect();            
        
    $query sprintf("SELECT page_keywords, page_description, page_title FROM pages WHERE page_file = %s");             
        
    $result mysql_query($query);        
        
    $result result_to_assoc($result);
        return 
    $result;      
       } 
    Now in my html file I have this (I have rewrite on, so urls will be /home or /our-team e.t.c.)
    PHP Code:
    <meta name="keywords" content="<?php
    $url 
    $_SERVER['REQUEST_URI'];
    $url preg_replace ('/\/testsite\//','',$url);
    $page $url;
    $keywords pages($page);   
     switch (
    $page)
          { 
            case 
    $keywords:
            echo 
    $keywords['page_keywords'];
                break;
        default:
        echo 
    "testing";
           }
    ?>">

  2. #2
    SitePoint Enthusiast
    Join Date
    Oct 2010
    Posts
    97
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Solved it needed single quotes around the %s duh!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •