php coding help |
Author: |
Message: |
Eljay
Elite Member
:O
Posts: 2949 Reputation: 77
– / / –
Joined: May 2004
|
O.P. php coding help
im in the middle of coding my website ( GameSmart)
and im doing the reviews section so i need to know how to include smilies
what i mean is like if somebody types :P then in the review it shows
how is this done?
This post was edited on 09-04-2004 at 06:24 PM by Eljay.
|
|
09-04-2004 05:26 PM |
|
|
fluffy_lobster
Veteran Member
Posts: -2
Posts: 1391 Reputation: 23
36 / /
Joined: Nov 2002
|
RE: how to include smilies
Before it is outputted, you need to pass it through str_replace:
code: $search = array('','');
$replace = array('<img src="img/tongue.gif">', '<img src="img/smile.gif">');
echo str_replace($search, $replace, $post):
That's an example of using it... customise it for yourself. You could also add the image code to each as you replace it in by doing a foreach loop
|
|
09-04-2004 05:59 PM |
|
|
Eljay
Elite Member
:O
Posts: 2949 Reputation: 77
– / / –
Joined: May 2004
|
O.P. RE: php coding help
ok thanx fluffy_lobster
now i need more help but not with smilies
i have a reviews section now with a couple of test reviews
but i want to load the review into an iframe using the id variable from the mysql db
heres the code i have:
code: <?
$username="*****";
$password="*****";
$database="*****";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM reviews";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
echo "<b><center>Review List</center></b><br><br>";
$i=0;
while ($i < $num) {
$id=mysql_result($result,$i,"id");
$Title=mysql_result($result,$i,"Title");
$Platform=mysql_result($result,$i,"Platform");
$Review=mysql_result($result,$i,"Review");
$Rating=mysql_result($result,$i,"Rating");
$Reviewer=mysql_result($result,$i,"Reviewer");
$Date=mysql_result($result,$i,"Date");
echo "
<table border=0 colspan=2>
<tr>
<td>
<a href="link to review" target="iframe">$Title</a>
</td>
<td><iframe goes here>
</tr>";
$i++;
}
?>
This post was edited on 09-04-2004 at 06:24 PM by Eljay.
|
|
09-04-2004 06:21 PM |
|
|
-dt-
Scripting Contest Winner
;o
Posts: 1819 Reputation: 74
36 / /
Joined: Mar 2004
|
RE: php coding help
you dont have to use echo to print html you can just close that part of the script with " ?>" and then writing all the html you want then using "<?" to start the php again then whenever you need to print a varible or something into the html just use <?echo "$whatever";?>
eg
code: <?
$username="*****";
$password="*****";
$database="*****";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM reviews";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
echo "<b><center>Review List</center></b><br><br>";
$i=0;
while ($i < $num) {
$id=mysql_result($result,$i,"id");
$Title=mysql_result($result,$i,"Title");
$Platform=mysql_result($result,$i,"Platform");
$Review=mysql_result($result,$i,"Review");
$Rating=mysql_result($result,$i,"Rating");
$Reviewer=mysql_result($result,$i,"Reviewer");
$Date=mysql_result($result,$i,"Date");
?>
<table border=0 colspan=2>
<tr>
<td>
<a href="link to review" target="iframe"><?echo "$Title";?></a>
</td>
<td><iframe goes here>
</tr>
<?
$i++;
}
?>
sorry if thats a little offtopic just thought he might like to know that.
and i dont quite get what you need help with
Happy Birthday, WDZ
|
|
09-05-2004 05:45 AM |
|
|
k776
Junior Member
Posts: 98 Reputation: 3
– / / –
Joined: Aug 2004
|
RE: php coding help
Using the way -dt- said, change the table to: code: <table border=0 colspan=2>
<tr>
<td>
<a href="<? echo "$Review";?>" target="iframe"><?echo "$Title";?></a>
</td>
<td><iframe name="iframe"></iframe>
</tr>
</table>
should do it. That what you looking for??
Edit: All you php know-alls out there. Fluffy lob gave the code (2nd message). I turned it into this: code: <?
$search = array('0star','1star','2star','3star','4star','5star');
$replace = array('Rating Coming Soon','<img src="images/download/star.gif">','<img src="images/download/star.gif"><img src="images/download/star.gif">','<img src="images/download/star.gif"><img src="images/download/star.gif"><img src="images/download/star.gif">','<img src="images/download/star.gif"><img src="images/download/star.gif"><img src="images/download/star.gif"><img src="images/download/star.gif">','<img src="images/download/star.gif"><img src="images/download/star.gif"><img src="images/download/star.gif"><img src="images/download/star.gif"><img src="images/download/star.gif">');
echo str_replace($search, $replace, $post);
?>
but it doesn't work, any idea why??
This post was edited on 09-05-2004 at 06:37 AM by k776.
|
|
09-05-2004 06:09 AM |
|
|
Jammie
New Member
Posts: 4
– / / –
Joined: Sep 2004
|
RE: php coding help
code: <?
$search = array('0star','1star','2star','3star','4star','5star');
$replace = array('Rating Coming Soon','<img src="images/download/star.gif">','<img src="images/download/star.gif"><img src="images/download/star.gif">','<img src="images/download/star.gif"><img src="images/download/star.gif"><img src="images/download/star.gif">','<img src="images/download/star.gif"><img src="images/download/star.gif"><img src="images/download/star.gif"><img src="images/download/star.gif">','<img src="images/download/star.gif"><img src="images/download/star.gif"><img src="images/download/star.gif"><img src="images/download/star.gif"><img src="images/download/star.gif">');
echo str_replace($search, $replace, $post);
?>
This code would output as blank as there is no value being past to the function within the $post variable. To make the code work you would need to use something along the lines of the following:
code: <?
$post = "0star 1star";
$search = array('0star','1star','2star','3star','4star','5star');
$replace = array('Rating Coming Soon','<img src="images/download/star.gif">','<img src="images/download/star.gif"><img src="images/download/star.gif">','<img src="images/download/star.gif"><img src="images/download/star.gif"><img src="images/download/star.gif">','<img src="images/download/star.gif"><img src="images/download/star.gif"><img src="images/download/star.gif"><img src="images/download/star.gif">','<img src="images/download/star.gif"><img src="images/download/star.gif"><img src="images/download/star.gif"><img src="images/download/star.gif"><img src="images/download/star.gif">');
echo str_replace($search, $replace, $post);
?>
Hope this helps
Jamie
|
|
09-05-2004 08:15 AM |
|
|
fluffy_lobster
Veteran Member
Posts: -2
Posts: 1391 Reputation: 23
36 / /
Joined: Nov 2002
|
RE: php coding help
First of all, if you want to use an iframe, you need an actual page which can be loaded into the iframe. The simplest way to do this is to make a page which fetches the review content of any of the reviews.
As per how to echo content, when you're incorporating variables into the string i much prefer lee's original method. Popping in and out of php mode is both messy and probably less efficient.
Also, mysql_result should only be used if you want a specific field. in your case, as you're using them all you can use mysql_fetch_array. This function returns false when you run out of rows, which saves you doing the count too.
Anyway... here is my revised version of the code. Because of the iframe it's split into two pages:
first of all the original page:
code: <?
$username="*****";
$password="*****";
$database="*****";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM reviews";
$result=mysql_query($query);
mysql_close();
?>
<b><center>Review List</center></b><br><br>
<table border=0>
<tr><td>
<table border=0>
<?
while ($row = mysql_fetch_array($result)) {
echo '
<tr>
<td>
<a href="iframe.php?id=' . $row['id'] . '" target="iframe">' . $row['Title'] . '</a>
</td></tr>';
}
?>
</table>
</td>
<td>
<iframe name="iframe" src="about:blank" width="400" height="300"></iframe>
</td>
</tr>
</table>
The html layout you started seemed a bit confusing. I've redone it the way I think you mean... change it back if it was meant to be different in the context of a whole page.
Then you have iframe.php which goes a little bit like this:
code: <?
$username="*****";
$password="*****";
$database="*****";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT Review FROM reviews WHERE id = $_GET[id]";
$result=mysql_query($query);
mysql_close();
echo mysql_result($result, 0);
?>
This post was edited on 09-05-2004 at 04:36 PM by fluffy_lobster.
|
|
09-05-2004 04:35 PM |
|
|
k776
Junior Member
Posts: 98 Reputation: 3
– / / –
Joined: Aug 2004
|
RE: php coding help
How do you write data/text to a database??
Im using my own form, set with method="post" action="scripts/add.php". What do I add in scripts/add.php??
Edit: I want to add the following feilds:
catid,
mplink,
name,
dllink,
desc,
rate,
type,
pic
to a table called download_items.
This post was edited on 09-06-2004 at 09:57 AM by k776.
|
|
09-06-2004 09:18 AM |
|
|
WDZ
Former Admin
Posts: 7106 Reputation: 107
– / /
Joined: Mar 2002
|
|
09-06-2004 09:33 AM |
|
|
k776
Junior Member
Posts: 98 Reputation: 3
– / / –
Joined: Aug 2004
|
RE: php coding help
Sorry WDZ, I meant to say infomation/text, not actual files
Also, what is a good php password code so stop visitors going into this page im making to put things into the database?? Maybe storing the username and password I choose in the database then asking for it?? Any help would be nice.
|
|
09-08-2004 05:30 AM |
|
|
Pages: (3):
« First
[ 1 ]
2
3
»
Last »
|
|
|