1

I'm writing a php code because I want to get a list of items from sql database and insert it in a post of my wordpress website. Since the items could be too many for a single post, I would like to change page every five items. So my goal is to add a wordpress tag after five items. Below is the code, but it doesn't work! It simply ignore the tag . Why? What is wrong? How can I get the same result? Thank you in advance for your help! I'm getting mad...

 $result = @mysql_query('SELECT * FROM wp01_frantoi WHERE wp01_frantoi.SIGLA = "VR"');

 if(!$result) {

   exit('<p>Error performing query: '.mysql_error().'</p>');

   }

$count = 1;




    while($row = mysql_fetch_array($result)) {

     $DENOMINAZIONE=$row['DENOMINAZIONE'];
     $SIGLA=$row['SIGLA'];
     $REGIONE=$row['REGIONE'];
     $PROVINCIA=$row['PROVINCIA'];
     $INDIRIZZO=$row['INDIRIZZO'];
     $CAP=$row['CAP'];
     $COMUNE=$row['COMUNE'];
     $FRAZIONE=$row['FRAZIONE'];
     $ALTRO=$row['ALTRO'];


if(($count % 5) == 0) { echo"<!--next page-->"; }

echo $DENOMINAZIONE."<br>".$INDIRIZZO."<br>".$CAP." - ".$COMUNE."<br>Provincia di ".$PROVINCIA."<br><br>";


$count = $count+1;


    }
  • 3
    @mysql_query - never use the @ operator, it's extremely bad practice to swallow errors like this rather than handling them. Also, don't use the mysql_ functions, that PHP extension id deprecated and your code will not run on newer versions of PHP. You should instead use PDO mysqli for general PHP work, and the wpdb class for WordPress work – Tom J Nowell Apr 6 '15 at 23:43
  • 1
    "It doesn't work" isn't a very helpful description, and I don't know what "it ignores the tag" means. What tag? Exactly what doesn't work? – s_ha_dum Apr 7 '15 at 0:01
0

wordpress uses <!--next page--> as a hint to paginate the content of a post only when it is in a content of a post. Your code produce direct HTML code in which <!--next page--> is just an html comment.

  • Ah ok, Thanks you Mark! It's clear now! And how can I manage this? How can I reach my goal? Thanks a lot for your suggestions... I'd like to change page every 5 items...is there a plugin? Or should I change the code? Ciao Gabriele – GabrieleG Apr 6 '15 at 23:08
  • It depends on what you actually do. One option is to create a post from your data, but it might not be possible if the data is dynamic. Another option is to create a custom post type and have each custom post show the data of one row and then an archive page can easily paginate, but in general if your data is fully dynamic you will need to write your own pagination. – Mark Kaplun Apr 7 '15 at 3:59

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