Forum Moderators: coopster
create table gallerie(
id int not null primary key auto_increment,
galname varchar(100),
url varchar(255)
);
i also made a html file to upload the info and it works.
Now i want to show(view/place) the info placed in galname on my site which is linked to the info placed in url.
so if i placed gallerie1 in my database under galname and
www.mygallerie.com/gal.html under url.
I want to place gallerie1 on my site which is linked to www.mygallerie.com/gal.html
I tried a few different ways but can't get it to work
I'm realy realy new at this.
can some one help me.
Thanks,
Norm
[edited by: jatar_k at 10:19 pm (utc) on Jan. 30, 2003]
[edit reason] delinked [/edit]
Database galleries;
Table gallerie in database galleries:
ID Gallerie name url
1 gallerie 01 [mysite...]
2 gallerie 02 [mysite...]
3 gallerie 03 [mysite...]
Now i want to show on my site:
gallerie 01
gallerie 02
gallerie 03
which are linked to the url given in the database.
So i want to put the info in a database and show it with php code.
Thanks,
Norm
very quick but that should work, should give you something like this
<p><a href="www.mysite/gal01.html">gallerie 01</a><br>
<a href="www.mysite/gal02.html">gallerie 02</a><br>
<a href="www.mysite/gal03.html">gallerie 03</a><br>
<?php
$sql = "SELECT * FROM gallerie";
$query = @mysql_query($sql);
while ($row = @mysql_fetch_array($query)) {
$ID = $row["ID"];
$galname = $row["galname"];
$url = $row["url"];
?>
<table>
<tr>
<td><?=$ID?>td>
<td><?=$galname?></td>
<td><a href="<?=$url?>"><?=$url?></a></td>
</tr>
</table>
<?php
}
?>
[edited by: RussellC at 10:51 pm (utc) on Jan. 30, 2003]
I bought a book the learn but as always i want to go to fast and just use what i need and noticed it does not work.
The examples in the book are not what i need and when i try to change it to what i want it does not work.
I 'am trying to insert the data like this:
$sql="insert into gallerie set
galname='$galname',
url='$url'";
if( @mysql_query($sql)) {
echo("<p>Your gallerie has been added.</p>");
}else{
echo("<p>Error adding submitted gallerie: " .
mysql_error() . "</p>");
}
It tels me that the gallerie has been added but when i look in the database(mysql) all it added was an ID the galname and url stay blank (If i enter the data directly in mysql its fine)
There might be something wrong with my code.
$sql="insert into gallerie values ('','" . $galname . "','" . $url . "')";
You can look here too
[mysql.com...]
<added>when testing I wouldn't use the @ symbol before your function calls, it suppresses errors. I use this to get the mysql error
mysql_query($sql) or die ("<BR>" . mysql_error() . "<BR>");
And a few other ways and it gives the message that the gallerie was added to the database but when i look in the database all thats added is the ID.
The field for galname and url stay blank
no mather what i tried it looks like it does not insert the data into the database.
Help
Thanks,
Norm
I had to edit my last post about 100 times because I kept making mistakes so let me break it down better.
$url = "www.mysite/gal01.html";
$galname = "gallerie 01";
query should look like this
insert into gallerie values ('','gallerie 01','www.mysite/gal01.html')
so we need to create this by using the variables. I rechecked that query and it is fine.
It looks like your vars don't have any values. You said you were using a form to insert the rows, I have a sneaking suspicion that the values aren't being passed properly or you are not accessing these values properly to attribute them to the vars.
if you are using a form you should have textboxes like so
<input type="text" name="galname">
<input type="text" name="url">
this will then use the post method to send to the script that does the inserting.
In that script you can access these vars by doing
$galname = $_POST['galname'];
$url = $_POST['url'];
then carrying on with your insert. You could test if the vars are receiving values by skipping the insert for now and doing something like this where your insert is now.
echo "<p>url: " . $url;
echo "<p>galname: " . $galname;
echo "<p>query: " . $sql;
this will show you all of the variables and you can better assess where the problem is.
While i'm "fighting" with this i learn more by the minute.
I think it is possible to get the same result with out using a database.
I made the following:
<!doctype html public "-//W3C//DTD HTML 4.0 //EN">
<html>
<head>
<title>Title here!</title>
<style type="text/css">
font-family:Normal,Helvetica;}
A:active{COLOR:#FF0000;FONT-FAMILY:normal;FONT-SIZE:12px;TEXT-DECORATION:none}
A:link{COLOR:#000000;FONT-FAMILY:normal;FONT-SIZE:12px;TEXT-DECORATION:none}
A:visited{COLOR:#000000;FONT-FAMILY:normal;FONT-SIZE:12px;TEXT-DECORATION:none}
a:hover{COLOR:#000080;FONT-FAMILY:normal;FONT-SIZE:12px;TEXT-DECORATION:underline}
</style>
</head>
<body>
<?php
$var2="http://wwww.mysite.com";
?>
<?php
$count= 1;
while ($count <= 10) {
echo'<a href="$var2">Gallerie</a><br />';
$count++;
}
?>
</body>
</html>
It outputs this:
Gallerie [mysite.com]
Gallerie [mysite.com]
Gallerie [mysite.com]
Gallerie [mysite.com]
Gallerie [mysite.com]
Gallerie [mysite.com]
Gallerie [mysite.com]
Gallerie [mysite.com]
Gallerie [mysite.com]
Gallerie [mysite.com]
I would like it to output This:
Gallerie 01 [mysite.com]
Gallerie 02 [mysite.com]
Gallerie 03 [mysite.com]
Gallerie 04 [mysite.com]
Gallerie 05 [mysite.com]
Gallerie 06 [mysite.com]
Gallerie 07 [mysite.com]
Gallerie 08 [mysite.com]
Gallerie 09 [mysite.com]
Gallerie 10 [mysite.com]
I tried and tried and are still trying.
Thanks,
Norm
printf [php.net]('<a href="%s/gallery_%02d">Gallerie %02d</a>', $var2, $i);
BTW I hope that the word Gallerie is not meant to be German since then it would need to be Galerie: Es kommt halt nicht von Galle ;).
Andreas
while ($i = mysql_fetch_array($result)){
echo "<a href='gallerie.php?id=$i[id]'>Gallerie $i[galname]</a><br />";
}
This should output the following HTML:
<a href='gallerie.php?id=1'>Gallerie 1</a><br />
<a href='gallerie.php?id=2'>Gallerie 2</a><br />
<a href='gallerie.php?id=3'>Gallerie 3</a><br />
etc...
Notice all links point to the same page but have a query string(?id=) at the end of the link. Now you create gallerie.php and put a SQL statement on that page that searches another table that holds the content for each gallerie.
You need to create a table for your gallerie items and make sure you have a gallerie_id field. This is how you control which items appear in each gallerie.
Am I making any sense to you? It can be a bit confusing at first, but it is a nice way to manage your site.