|
-
May 22nd, 2010, 04:03 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] my first php page
hi all
i have a web page im working on, my first php page ever and im stuck with pictures
i want to add a picture to ever row of my search on the db
the picture is store under the localhost server but i cant get it to work. example below
PHP Code:
<img border=0img src="//localhost/vidpics/videotitle.jpg" width=40 height=40>
on the image bit i need tobe able to use localhost not servers name and the image title(videotitle) needs to be able to change to each row.
PHP Code:
<?php
/* Change next two lines */
$db="vdidb";
$link = mysql_connect('localhost: 3306', 'user', 'password');
if (! $link)
die(mysql_error());
mysql_select_db($db , $link)
or die("Couldn't open $db: ".mysql_error());
// $result = mysql_query( "SELECT vidnumber, videotitle, age, Runningtime, starring, hd, trilogy FROM videolist")
$id = "%".$_GET["search"]."%";
// $result = mysql_query( "SELECT vidnumber, videotitle, age, Runningtime, werestoredFolder FROM videolist WHERE videotitle LIKE '".mysql_real_escape_string($id)."'")
$result = mysql_query( "SELECT vidnumber, videotitle, age, Runningtime FROM videolist WHERE vidnumber LIKE '".mysql_real_escape_string($id)."'")
or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result);
// print "There are $num_rows records.<P>";
print "<table width=200 border=1>\n";
while ($get_info = mysql_fetch_row($result)){
print "<tr>\n";
foreach ($get_info as $field)
print "\t<td>$field</td>\n";
print "</tr>\n";
}
print "</table>\n";
print "There are $num_rows records.<P>";
mysql_close($link);
?>
<br>
<body>
programming pc: laptop. running xp pro and vb.net..
media centre xp pc: dual core 6000,4gb memory, 1tb harddrive
mainserver: server 2008, 8gb memory, amd e-350 dual core, 6tb harddrive and local web host
atomvault 1: server 2008, atom 330 with 4 gb memory, 35TB hardrive space for videos and music..
backup pc : xp, 4gb, atom 330, 10tb harddrive(web, pictures, music, databases)
2 x video backup: atom 330, 2gb, 18tb harddrive
everything on remote login..
check out my builds http://AtomVaults.yolasite.com
learning vb.net and php + mysql   - got most of the basics now.
I WISH THERE WAS MORE TIME IN THE DAY  
-
May 22nd, 2010, 06:54 AM
#2
Re: my first php page
Moved From The PHP CodeBank
-
May 22nd, 2010, 10:59 AM
#3
Re: my first php page
is the path you're using for the image not resolving? or, what's wrong? you haven't done anything with your code that adds an image tag or anything.
I'm not even sure you'd be able to use a path like that to resolve an image. what are you referring to when you say "localhost server"? a server called localhost, or the local machine that you're working on? if it's the local machine, you should put those images into your webserver's public directory and refer to them using an HTTP URL: http://localhost/vidpics/
-
May 23rd, 2010, 05:33 AM
#4
Thread Starter
Hyperactive Member
Re: my first php page
hi kows
ive sorted the picture problem, i have put them in a public directory .
http://localhost/vidpics/ i can now pull them up using
PHP Code:
<img border=0img src="/vidpics/videotitle.jpg" width=40 height=40>
im want to load a picture for each video title on the list table but not even sure were to start.
programming pc: laptop. running xp pro and vb.net..
media centre xp pc: dual core 6000,4gb memory, 1tb harddrive
mainserver: server 2008, 8gb memory, amd e-350 dual core, 6tb harddrive and local web host
atomvault 1: server 2008, atom 330 with 4 gb memory, 35TB hardrive space for videos and music..
backup pc : xp, 4gb, atom 330, 10tb harddrive(web, pictures, music, databases)
2 x video backup: atom 330, 2gb, 18tb harddrive
everything on remote login..
check out my builds http://AtomVaults.yolasite.com
learning vb.net and php + mysql   - got most of the basics now.
I WISH THERE WAS MORE TIME IN THE DAY  
-
May 25th, 2010, 11:29 AM
#5
Thread Starter
Hyperactive Member
Re: my first php page
can someone help me with this please
programming pc: laptop. running xp pro and vb.net..
media centre xp pc: dual core 6000,4gb memory, 1tb harddrive
mainserver: server 2008, 8gb memory, amd e-350 dual core, 6tb harddrive and local web host
atomvault 1: server 2008, atom 330 with 4 gb memory, 35TB hardrive space for videos and music..
backup pc : xp, 4gb, atom 330, 10tb harddrive(web, pictures, music, databases)
2 x video backup: atom 330, 2gb, 18tb harddrive
everything on remote login..
check out my builds http://AtomVaults.yolasite.com
learning vb.net and php + mysql   - got most of the basics now.
I WISH THERE WAS MORE TIME IN THE DAY  
-
May 25th, 2010, 11:54 AM
#6
Re: my first php page
If you don't already have one, make a column on your table that holds the image name. Then, as you're outputting the table data, you'll need to identify which column is the image name, and output that column as an HTML img tag. So, one idea:
PHP Code:
?> <table width=200 border=1> <?php while ($get_info = mysql_fetch_array($result)){ ?> <tr> <?php //get the names of your table columns into an array: $keys = array_keys($get_info); $keys = array_filter($keys, function($var){return !is_numeric($var);}); for($i=0;$i<count($get_info);$i++){ ?><td><?php //if you find the name of the image column, output an img tag, //otherwise just output the field data: if($keys[$i] == "imgName"){ ?><img border=0 src="/vidpics/<?php echo $get_info[$i];?>" width=40 height=40><?php }else{ echo $get_info[$i]; } ?></td><?php } ?></tr><?php } ?> </table> <?php
Edit: changed the code a bit because it wouldn't have actually worked with mysql_fetch_row().
Last edited by SambaNeko; May 25th, 2010 at 12:04 PM.
-
May 25th, 2010, 02:24 PM
#7
Re: my first php page
get rid of all the extra code there and simply use mysql_fetch_assoc() to return an associative array of values; dealing with numeric keys is a bad idea when dealing with database information -- if the table is altered, all of your code might need to be altered.
PHP Code:
<?php while ($get_info = mysql_fetch_assoc($result)){ ?> <tr> <?php //get the names of your table columns into an array: foreach($get_info as $key => $value){ ?><td><?php //if you find the name of the image column, output an img tag, //otherwise just output the field data: if($key == "imgName"){ ?><img border=0 src="/vidpics/<?php echo $value;?>" width=40 height=40><?php }else{ echo $value; } ?></td><?php } ?></tr><?php } ?>
oh yeah, and be aware that while Samba's method would work, closures/anonymous functions aren't available until PHP 5.3 (and lots of people/hosts still haven't upgraded).
Last edited by kows; May 25th, 2010 at 02:33 PM.
-
May 25th, 2010, 02:32 PM
#8
Re: my first php page
if the table is altered, all of your code might need to be altered.
If you're referring to a specific numeral, yes. And the same is true of associative keys if you refer to a specific column name (if it changes, there goes your code). Right? So [in this particular case] I wouldn't say either is inherently preferential.
Which is not to say your code sample isn't better - it is.
-
May 25th, 2010, 02:40 PM
#9
Re: my first php page
oh, no -- I know that your code didn't actually use numeric keys! I was just saying, for information sake, that dealing with numeric keys and database tables is a bad idea. in general though, you don't often change the name of database table fields once the database has been designed. however, you may sometimes add new fields or re-order the fields (which could potentially break the way numeric keys are referenced in your code). that's all.
-
May 26th, 2010, 08:19 AM
#10
Thread Starter
Hyperactive Member
Re: my first php page
hi
thanks for the picture post it has helped me figure out how picture are loaded.
im stuck with the table, i want it to look like in the table. but i can figure it out
picture | video number | video title
PHP Code:
$result = mysql_query( "SELECT vidnumber, videotitle, age, Runningtime FROM videolist WHERE vidnumber LIKE '".mysql_real_escape_string($id)."'")
or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result);
// print "There are $num_rows records.<P>";
print "<table width=200 border=1>\n";
while ($get_info = mysql_fetch_row($result)){
print "<tr>\n";
foreach ($get_info as $field)
print "\t<td>$field</td>\n";
// $field needs tobe the video title
?><img border=0 src="/vidpics/<?php echo $field;?>.jpg" width=40 height=40><?php
print "</tr>\n";
}
print "</table>\n";
mysql_close($link);
?>
<br>
<body>
programming pc: laptop. running xp pro and vb.net..
media centre xp pc: dual core 6000,4gb memory, 1tb harddrive
mainserver: server 2008, 8gb memory, amd e-350 dual core, 6tb harddrive and local web host
atomvault 1: server 2008, atom 330 with 4 gb memory, 35TB hardrive space for videos and music..
backup pc : xp, 4gb, atom 330, 10tb harddrive(web, pictures, music, databases)
2 x video backup: atom 330, 2gb, 18tb harddrive
everything on remote login..
check out my builds http://AtomVaults.yolasite.com
learning vb.net and php + mysql   - got most of the basics now.
I WISH THERE WAS MORE TIME IN THE DAY  
-
May 26th, 2010, 08:25 AM
#11
Re: my first php page
you have to copy all of the code from the examples for them to work -- not just one or two lines.
-
May 26th, 2010, 10:31 AM
#12
Thread Starter
Hyperactive Member
Re: my first php page
hi kows
its work thanks.
how do i add more coloms so it looks like
picture | video number | video title
programming pc: laptop. running xp pro and vb.net..
media centre xp pc: dual core 6000,4gb memory, 1tb harddrive
mainserver: server 2008, 8gb memory, amd e-350 dual core, 6tb harddrive and local web host
atomvault 1: server 2008, atom 330 with 4 gb memory, 35TB hardrive space for videos and music..
backup pc : xp, 4gb, atom 330, 10tb harddrive(web, pictures, music, databases)
2 x video backup: atom 330, 2gb, 18tb harddrive
everything on remote login..
check out my builds http://AtomVaults.yolasite.com
learning vb.net and php + mysql   - got most of the basics now.
I WISH THERE WAS MORE TIME IN THE DAY  
-
May 26th, 2010, 11:43 AM
#13
Thread Starter
Hyperactive Member
Re: my first php page
hi
ive got the picture to load with video title next to it by using value i just cant get any of the of coloms ie age video number to put next the the picture
PHP Code:
$result = mysql_query( "SELECT videotitle, age, Runningtime FROM videolist WHERE vidnumber LIKE '".mysql_real_escape_string($id)."'")
or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result);
// print "There are $num_rows records.<P>";
print "<table width=300 border=1>\n";
while ($get_info = mysql_fetch_row($result)){
// <?php while ($get_info = mysql_fetch_assoc($result)){ ?>
<tr>
<?php
//get the names of your table columns into an array:
foreach($get_info as $key => $value){
?><td><?php
//if you find the name of the image column, output an img tag,
//otherwise just output the field data:
if($key == "imgName"){
?><img border=0 src="/vidpics/<?php echo $value;?>web.jpg" width=60 height=60><?php
echo "</td><td>";
echo $value;
echo "</td><td>";
// im wanting to add video title and video number here
// value is the video title but i cant get anything else
echo $value;
}else{
// echo $value;
}
?></td><?php
}
?></tr><?php
}
?>
programming pc: laptop. running xp pro and vb.net..
media centre xp pc: dual core 6000,4gb memory, 1tb harddrive
mainserver: server 2008, 8gb memory, amd e-350 dual core, 6tb harddrive and local web host
atomvault 1: server 2008, atom 330 with 4 gb memory, 35TB hardrive space for videos and music..
backup pc : xp, 4gb, atom 330, 10tb harddrive(web, pictures, music, databases)
2 x video backup: atom 330, 2gb, 18tb harddrive
everything on remote login..
check out my builds http://AtomVaults.yolasite.com
learning vb.net and php + mysql   - got most of the basics now.
I WISH THERE WAS MORE TIME IN THE DAY  
-
May 26th, 2010, 03:58 PM
#14
Thread Starter
Hyperactive Member
Re: my first php page
solved my table problem.
is there any table tut that i can look at as a point of ref.
im wanting a table like this in a table
________________________________
| | title |
| picture | age | running | number |
| | |
|_______| description |
________________________________|
programming pc: laptop. running xp pro and vb.net..
media centre xp pc: dual core 6000,4gb memory, 1tb harddrive
mainserver: server 2008, 8gb memory, amd e-350 dual core, 6tb harddrive and local web host
atomvault 1: server 2008, atom 330 with 4 gb memory, 35TB hardrive space for videos and music..
backup pc : xp, 4gb, atom 330, 10tb harddrive(web, pictures, music, databases)
2 x video backup: atom 330, 2gb, 18tb harddrive
everything on remote login..
check out my builds http://AtomVaults.yolasite.com
learning vb.net and php + mysql   - got most of the basics now.
I WISH THERE WAS MORE TIME IN THE DAY  
-
May 27th, 2010, 07:50 AM
#15
Thread Starter
Hyperactive Member
Re: my first php page
i use below to get picture and video title and it works perfect, i now wanting to change and add table layout.
how do i marry the two together to give me the finished page
PHP Code:
<html>
<head><title>video list basic</title>
<style type="text/css">
td {font-family: tahoma, arial, verdana; font-size: 10pt }
</style>
</head>
<body>
<?php
/* Change next two lines */
$db="vdidb";
$link = mysql_connect('localhost: 3306', 'user', 'password');
if (! $link)
die(mysql_error());
mysql_select_db($db , $link)
or die("Couldn't open $db: ".mysql_error());
// $result = mysql_query( "SELECT vidnumber, videotitle, age, Runningtime, starring, hd, trilogy FROM videolist")
$id = "%".$_GET["search"]."%";
// $result = mysql_query( "SELECT vidnumber, videotitle, age, Runningtime, werestoredFolder FROM videolist WHERE videotitle LIKE '".mysql_real_escape_string($id)."'")
$result = mysql_query( "SELECT vidnumber, videotitle, age, Runningtime FROM videolist WHERE vidnumber LIKE '".mysql_real_escape_string($id)."'")
or die(mysql_error());
echo "<table border='1'>";
// echo "<table align= center>";
// echo "<tr><th>picture</th><th>vid number</th><th>video title</th></tr>";
while($row = mysql_fetch_array($result)){
echo "<tr><td>";
?><img border=0 src="/vidpics/<?php echo $row['videotitle'];?>web.jpg" width=80 height=80><?php
echo "<td><td>";
echo $row['vidnumber'];
echo "</td><td>";
echo $row['videotitle'];
echo "</td><td>";
echo $row['age'];
}
echo "</table>";
//}
i have made up the table i want to use below
HTML Code:
<table border="1" width="62%" height="126">
</tr>
<tr>
<td width="20%" rowspan="4" height="120"><p align="center">picture</p></td>
<td width="20%" height="19"><p align="center">number</p></td>
<td width="60%" colspan="3" height="19"><p align="center">title</p></td>
</tr>
<tr>
<td width="20%" height="14"><p align="center">imdb</p></td>
<td width="20%" height="14"><p align="center">age</p></td>
<td width="20%" height="14"><p align="center">empty</p></td>
<td width="20%" height="14"><p align="center">running</p></td>
</tr>
<tr>
<td width="20%" height="25"><p align="center">director</p></td>
<td width="20%" height="25"><p align="center">starring</p></td>
<td width="20%" height="25"><p align="center">trilogy</p></td>
<td width="20%" height="25"><p align="center">hd</p></td>
</tr>
<tr>
<td width="80%" height="38" colspan="4">plot</td>
</tr>
</table>
programming pc: laptop. running xp pro and vb.net..
media centre xp pc: dual core 6000,4gb memory, 1tb harddrive
mainserver: server 2008, 8gb memory, amd e-350 dual core, 6tb harddrive and local web host
atomvault 1: server 2008, atom 330 with 4 gb memory, 35TB hardrive space for videos and music..
backup pc : xp, 4gb, atom 330, 10tb harddrive(web, pictures, music, databases)
2 x video backup: atom 330, 2gb, 18tb harddrive
everything on remote login..
check out my builds http://AtomVaults.yolasite.com
learning vb.net and php + mysql   - got most of the basics now.
I WISH THERE WAS MORE TIME IN THE DAY  
-
May 27th, 2010, 11:13 AM
#16
Thread Starter
Hyperactive Member
Re: my first php page
hi
i managed to finish the search with the table layout. it looks good aswell
thanks for all your help
programming pc: laptop. running xp pro and vb.net..
media centre xp pc: dual core 6000,4gb memory, 1tb harddrive
mainserver: server 2008, 8gb memory, amd e-350 dual core, 6tb harddrive and local web host
atomvault 1: server 2008, atom 330 with 4 gb memory, 35TB hardrive space for videos and music..
backup pc : xp, 4gb, atom 330, 10tb harddrive(web, pictures, music, databases)
2 x video backup: atom 330, 2gb, 18tb harddrive
everything on remote login..
check out my builds http://AtomVaults.yolasite.com
learning vb.net and php + mysql   - got most of the basics now.
I WISH THERE WAS MORE TIME IN THE DAY  
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|