Practical PHP

  • Increase font size
  • Default font size
  • Decrease font size
Home mysqlphp-writer MySqlPHP help Php code generated - explained. Part 1, Table

Php code generated - explained. Part 1, Table

E-mail Print

 Table - output of a datbase-table into a html-table.

 The PHP code that is generated by the mysqlphpwriter is very simple. It is simple for a single reason, it is meant as a starting point for your work, and not as finished code. mysqlphpwriter does not generate code that will work at once, you have to make some small modifications to fit your needs.

 This is done for a reason: Almost always some small special tweaks have to be done. And we have decided that the best thing to do is to present the same structure always from the script, and when you get used to it after using it once or twice, you know exactly what to modify. This means there are very few options - you just click, copy and paste.

 We use the first table from joomla as example. Seen from phpMyAdmin it looks like this:

 

 In order to make a php-script that will output this into a table we go to our mysqlphpwriter, and get the following in our browser:

 Click on "Table" under the grey "php-code header", next to the "jos_banner".

 

This outputs the following code:

 

function jos_banner_list($bid){ 
$sql ="
SELECT bid, cid, type, name
, alias, imptotal, impmade, clicks imageurl , clickurl , date
, showBanner checked_out checked_out_time editor, custombannercode catid, description
, sticky, ordering, publish_up, publish_down, tags, params
FROM jos_banner
WHERE '$bid' = bid ";
$delimiter = "</td><td>";
print "<table>";
$result=mysql_query($sql);
$num_rows = mysql_num_rows($result);
while($o = mysql_fetch_array($result)){
print "<tr> <td>";
print $o["bid"] ;
print $delimiter;
print $o["cid"] ;
print $delimiter;
print $o["type"] ;
print $delimiter;
print $o["name"] ;
print $delimiter;
print $o["alias"] ;
print $delimiter;
print $o["imptotal"] ;
print $delimiter;
print $o["impmade"] ;
print $delimiter;
print $o["clicks"] ;
print $delimiter;
print $o["imageurl"] ;
print $delimiter;
print $o["clickurl"] ;
print $delimiter;
print $o["date"] ;
print $delimiter;
print $o["showBanner"] ;
print $delimiter;
print $o["checked_out"] ;
print $delimiter;
print $o["checked_out_time"] ;
print $delimiter;
print $o["editor"] ;
print $delimiter;
print $o["custombannercode"] ;
print $delimiter;
print $o["catid"] ;
print $delimiter;
print $o["description"] ;
print $delimiter;
print $o["sticky"] ;
print $delimiter;
print $o["ordering"] ;
print $delimiter;
print $o["publish_up"] ;
print $delimiter;
print $o["publish_down"] ;
print $delimiter;
print $o["tags"] ;
print $delimiter;
print $o["params"] ;
print "</td> </tr>";
}
mysql_free_result($result);
print "</table>";
}

 As you can see, it generates a lot of code.

There are 3 blocks, basically setting up the SQL, running the query, and dumping out the content.

Now you need to make the changes you need. Remeber, this is not probably what you want.

But with a modification of the "where-clause" in the sql this is suddenly very usefull:

WHERE '$bid' > bid "

 Then we get all values out of the function. As you probably noticed, the script generates a complete function.

 

 

 
 

Main Menu


Warning: Parameter 1 to modMainMenuHelper::buildXML() expected to be a reference, value given in /usr/www/users/infostil/www.practical-php.com/libraries/joomla/cache/handler/callback.php on line 99