Forum Moderators: coopster
Yeah i went to the link that u gave ...its really puzzling for me..
can u make one very simple one... all i need is to extract a ddata from mysql and display it in browser .. dynamically ..
Assum my table looks like this ¦ID¦Image¦Description¦
i wanted that Image and Description to be displayed it on Browser , i dont need any forms .. as am trying to learn just to retrive it.
So do u mind teaching me plaese
will count on u
thanks a lot
for step3 that exact query won't work for you but you could use something as simple as
$sql = "select * from ourtablename";
that will grab all of the columns from each row
then for step5 you will obviously need to change the echo line to fit your data
this wont work for you
echo "<p>",$row['id'],": ",$row['manufacturer'];
maybe something like this to start
echo "<p>",$row['column1'];
echo "<br>",$row['column2'];
echo "<br>",$row['column3'];
all the tablenames and column names will have to be changed to the ones you use but everything else is in that tutorial
I admire your go-for-it-ness in wanting to start out using SQL, but if the tutorial link above didn't do it for you (it's a pretty straightforward tutorial, and very well-written), and googling neither, probably it's time to wait a bit with SQL. There's plenty you can learn and accomplish hacking PHP code by adding stuff you need / commenting out stuff without touching the SQL part, and you'll find that once you're more comfortable with PHP in general and things like arrays, the SQL then will come really easy.
Another good way of learning is to download a couple of free scripts from Hotscripts.com that use SQL/PHP and see how they are coded. Looking at other peoples code can be a great learning curve. On the other hand, sometimes you can look at things until you are blue in the face and not understand it. Another time it all falls into place. You just have to keep going over it. I think its part of the fun in learning.
Hope you find something that suits you.
:)
This is the code am trying : have a look am getting error, if u all can fixed it up for me :
am getting error on this line : Parse error: parse error in c:\web\test.php on line 12
***************************************************
<html><body>
<?
$host = "localhost";
$user = "root";
$pass = "";
$dbname = "karmas";
$connection = mysql_connect($host,$user,$pass) or die (mysql_errno().": ".mysql_error()."<BR>");
mysql_select_db($dbname)
$sql = "SELECT ID,logo,Description FROM client";
$result = mysql_query ($sql);
while ($row = mysql_fetch_row($result))
{
$ID = $row[0];
$logo = $row[1];
$Description = $row[2];
$show_stuff .= "<img src=\"$image_path\"><br>$image_description";
// ^^^ this will store all the values of table inside $show_stuff ^^^
}
echo $show_stuff;
?>
</body></html>
************************************************
My Table structure (karmas)
¦ID¦logo¦Description¦
*****************************************************
Parse error: parse error in c:\web\test.php on line 12
($sql = "SELECT ID,logo,Description FROM client"; )
this will get ya many times during your learning of php.. and even when you know it well.. always check the lines above and below the specified error line.
sometimes a bit tricky when large blocks missing an opening or closing curly brace is part of the error.
echo "<table>";
echo "<th>ID</th><th>Logo</th><th>Description</th>";while ($row = mysql_fetch_row($result)){
echo "<td>$row[0]</td>";
echo "<td>$row[1]</td>";
echo "<td>$row[2]</td>";
}
echo "</table>";
$show_stuff .= "<img src=\"$image_path\"><br>$image_description";
$show_stuff .= "<img src=\"image_path/".$logo."\"><br>ID: ".$ID."<br>Description: ".$Description."<br>";
You can also use this script, but you'll have to modify it a little bit to make it do what you want (yeah, go figure out how! It'll be worth it!):
$host = "localhost";
$user = "root";
$pass = "";
$dbname = "karmas";
$table = "client";
$connection = mysql_connect($host,$user,$pass) or die (mysql_errno().": ".mysql_error()."<BR>");
mysql_select_db($dbname);
$sql = "SELECT * FROM ".$table;
$result = mysql_query ($sql);
$resultrows = array();
while($row = mysql_fetch_assoc($result)){
$resultrows[] = $row;
}
echo '<table>'."\n";
foreach($resultrows as $k => $v){
echo "\n".'<!-- this is the beginning of the foreach $resultrows loop, loop number '.$k.'-->';
echo "\n".'<tr><td>'.$k.'</td>';
foreach($v as $k1 => $v1){
echo "\n".'<!-- here we are doing a loop of the foreach $v loop (inside the foreach $resultrows loop -->';
echo "\n".'<td><b>'.$v1.'</b>: '.htmlspecialchars($k1).'</td>';
}
echo '</tr>';
}
echo "\n".'</table>';
echo '<table>'."\n";-- don't change the query. 'View source' for a bit more help / clues.
Really thnks for help , and i just wonder how do i give my image source , its puzzling for me i dont no how .... can u add me one thing in that code ..
my data structure is like this .. ID¦logo¦Description so all i need to retrive is Logo and Description ,
can u do that for me plz , and also a image src to that logo.
thanks will count to ya all
To make things much simpler (and clearer) could u answers these qusetions first..
a) How & why have used $image_path, do u know what it does?
b) What goes in the Logo field in the table? Is it the file name of the logo? Could you give an example.
c) where are the actual logos (images} located in your server.
OK, here's some code again
<html><body>
<!-- -->
<?
$host = "localhost";
$user = "root";
$pass = "";
$dbname = "karmas";
$connection = mysql_connect($host,$user,$pass) or die (mysql_errno().": ".mysql_error()."<BR>");
mysql_select_db($dbname);
// ignore the double slashes (there as spaceholders)
$sql = "SELECT ID,logo,Description FROM client";
$result = mysql_query ($sql);
$image_path = '/imagedirectory';
//
//
//
while ($row = mysql_fetch_row($result))
{
//
$ID = $row[0];
$logo = $row[1];
$Description = $row[2];
//
$show_stuff .= "<img src=\"".$image_path."/".$logo."\"><br>ID: ".$ID."<br>Description: ".$Description."<br>";
//
// ^^^ this will store all the values of table inside $show_stuff ^^^
// ^^^ above comment probably from some earlier code, not for this code ^^^
}
//
echo $show_stuff;
?>
</body></html>
On the line
$image_path = '/imagedirectory', replace "
/imagedirectory' with the images' location (directory they're in).
Zipper: the second snippet is primarily a learning thing - it just shows all the field names and field contents of any table you set as
$table. One always holds out that little bitty hope that we're also teaching to code, not just writing free scripts ;)
******************************************************
<?php
$hostname_conn = "localhost";
$database_conn = "karmas";
$username_conn = "root";
$password_conn = "";
$conn = mysql_pconnect($hostname_conn, $username_conn, $password_conn) or trigger_error(mysql_error(),E_USER_ERROR);
?>
<?php
$maxRows_Recordset1 = 6;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
$pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;
mysql_select_db($database_conn, $conn);
$query_Recordset1 = "SELECT * FROM client";
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $conn) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
if (isset($_GET['totalRows_Recordset1'])) {
$totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
$all_Recordset1 = mysql_query($query_Recordset1);
$totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
?>
<table border="1" cellspacing="0" bordercolor="#000000">
<tr bgcolor="#999999">
<td><strong>pic_url</strong></td>
<td><strong>pic_description</strong></td>
</tr>
<?php do {?>
<tr>
<td><?php echo "<img src=";?>
<?php echo $row_Recordset1['logo'];?><?php echo ">";?></td>
<td><?php echo $row_Recordset1['Description'];?></td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));?>
</table>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
also, you don't have to open/close php tags for each line.. for an example, this one
<?php echo $row_Recordset1['logo'];?><?php echo ">";?>
can be easily coded as,
<?php echo $row_Recordset1['logo'].">";?>
hope it goes well for you.
The code u all gave me was not bad too ... just that i couldnt get what i wanted it . like say in dynamic table .. now i got it..Hurray lol
Thanks to ya all.. I will trouble u all next time if ya all dont mind ..as am trying to learn myself..
Kading Cha = Thanks