Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. PDO Return Single Result, How To Return Different Record From 1 Column Multiple Rows

PDO Return Single Result, How To Return Different Record From 1 Column Multiple Rows

Scheduled Pinned Locked Moved Database
databasehelpmysqlcomxml
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 13235099
    wrote on last edited by
    #1

    I am making a custom Sitemap from my database and stuck with following Issue SQL Query:

    SELECT term_id FROM wp_term_taxonomy WHERE taxonomy="product-cat" || taxonomy="product-brand"

    Query Output term_id 365 369 370 It returns all term_id from my database through which I gather category slugs from another table to make sitemap URLs. Below is the code and it works fine as you can see in (sitemap output), but unfortunately I am unable to extract next row term_id & it shows always same term_id to me as a result 'Same URL' My Sitemap Output

    http://domain.com/search-page/?product-cat=mobiles-tablets 365
    always
    1.0

    http://domain.com/search-page/?product-cat=mobiles-tablets 365
    always
    1.0

    CODE

    ';
    $xml.= "\n".'';
    $db = new PDO('mysql:host=xxx;dbname=xxx', 'xx', 'xxx');
    $stmt[$i] = $db->query('SELECT count(*) FROM wp_term_taxonomy WHERE taxonomy="product-cat" || taxonomy="product-brand"');
    $rowcount = $stmt[$i]->fetchColumn();
    for ($i=0; $i<2; $i++)
    {
    $sth[$i] = $db->query('SELECT term_id FROM wp_term_taxonomy WHERE taxonomy="product-cat" || taxonomy="product-brand"');
    $t_id[$i] = $sth[$i]->fetchColumn();
    $stmt[$i] = $db->query('SELECT taxonomy FROM wp_term_taxonomy WHERE term_id = '.$t_id[$i].'');
    $t_taxonomy[$i] = $stmt[$i]->fetchColumn();
    $stmt[$i] = $db->query('SELECT slug FROM wp_terms WHERE term_id = '.$t_id[$i].'');
    $t_slug[$i] = $stmt[$i]->fetchColumn();
    }
    echo $xml;
    for ($i=0; $i<2; $i++)

      {
    
        $xml.= "\\n\\t\\t".''."\\n";
    
    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups