What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » php coding help

Pages: (3): « First [ 1 ] 2 3 » Last »
2 votes - 5 average   php coding help
Author: Message:
Eljay
Elite Member
*****

Avatar
:O

Posts: 2949
Reputation: 77
30 / Male / Flag
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 :P
how is this done?

This post was edited on 09-04-2004 at 06:24 PM by Eljay.
09-04-2004 05:26 PM
Profile PM Find Quote Report
fluffy_lobster
Veteran Member
*****

Avatar
Posts: -2

Posts: 1391
Reputation: 23
31 / Male / Flag
Joined: Nov 2002
RE: how to include smilies
Before it is outputted, you need to pass it through str_replace:

code:
$search = array(':P',':)');
$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
Profile E-Mail PM Web Find Quote Report
Eljay
Elite Member
*****

Avatar
:O

Posts: 2949
Reputation: 77
30 / Male / Flag
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
Profile PM Find Quote Report
-dt-
Scripting Contest Winner
*****

Avatar
;o

Posts: 1819
Reputation: 74
30 / Male / Flag
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
[Image: dt2.0v2.png]      Happy Birthday, WDZ
09-05-2004 05:45 AM
Profile PM Web Find Quote Report
k776
Junior Member
**

Avatar

Posts: 98
Reputation: 3
– / Male / –
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.
[Image: k776.jpg]
09-05-2004 06:09 AM
Profile PM Web Find Quote Report
Jammie
New Member
*


Posts: 4
– / Male / –
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 :D

Jamie
09-05-2004 08:15 AM
Profile E-Mail PM Web Find Quote Report
fluffy_lobster
Veteran Member
*****

Avatar
Posts: -2

Posts: 1391
Reputation: 23
31 / Male / Flag
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
Profile E-Mail PM Web Find Quote Report
k776
Junior Member
**

Avatar

Posts: 98
Reputation: 3
– / Male / –
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.
[Image: k776.jpg]
09-06-2004 09:18 AM
Profile PM Web Find Quote Report
WDZ
Former Admin
*****

Avatar

Posts: 7107
Reputation: 107
– / Male / Flag
Joined: Mar 2002
RE: php coding help
quote:
Originally posted by k776
How do you write files to a database??

Im using my own form, set with method="post" action="scripts/add.php". What do I add in scripts/add.php??
http://www.php.net/manual/en/features.file-upload.php
http://p2p.wrox.com/topic.asp?TOPIC_ID=11883

Those links should point you in the right direction... :p
09-06-2004 09:33 AM
Profile PM Web Find Quote Report
k776
Junior Member
**

Avatar

Posts: 98
Reputation: 3
– / Male / –
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.
[Image: k776.jpg]
09-08-2004 05:30 AM
Profile PM Web Find Quote Report
Pages: (3): « First [ 1 ] 2 3 » Last »
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On