Jul 24, 2008

A Lot Of Php Questions Part 2

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming

free web hosting

A Lot Of Php Questions Part 2

karlo
Ok, here's another. After looking at many PHP codes, I will call it "PHP Shortcuts". Do you still know any other "PHP Shortcuts"?

Example, to "print" the visitor's IP address, I use
CODE
<html><head></head><body><?php print $_SERVER['REMOTE_ADDR']; ?></body></html>
After seeing someone's codes, I saw an easy way
CODE
<?=$_SERVER['REMOTE_ADDR'];?>
So, you know any more of that?

And for MySQL, I know there are many ways to retrieve the results. But how? Can you really teach me on how to use MySQL in PHP? Especially in LOOPS. I'm planning to create my own CMS. Please help me again. For my first thread, thank you all for helping me. But in this new thread, please help me!

Reply

OpaQue
Refer this tutorial posted at our other site astahost.

http://www.astahost.com/Writing-A-Generic-...ript-t2659.html

Hope that helps.

Reply

mobious
remember that your shortcut method will only work if the short_open_tag config is set to true. anyways for the shortcuts that i know...

another way of writing this:

CODE
if ("red" == "red") {
print "red";
} else {
print "not red";
}


is this way...

CODE
"red" == "red" ? print "red" : print "not red";


this is the standard format:

CODE
[condition] ? [codes to bexecuted when true] : [codes to be executed when false]


for your mysql question... i have a simple loop for you. it may be simple but the product of your loop will be a multi-dimensional array. don't mind the code ok. it's just an example.

CODE
$sql = "SELECT *
FROM armor
WHERE armor_type = '{$type}'
  AND SUBSTRING(armor_name, 1, 1) LIKE '{$first_letter}'
ORDER BY armor_name ASC";

if(!($result = mysql_query($sql))) {
die(mysql_error());
}

while ($item[] = mysql_fetch_array($result, MYSQL_ASSOC));

//do the processing of data here. i always use a for.. loop.

for ($x = $start; $x < $display_item; $x++) {
if ($item[$x]['armor_sold'] == "") {
 $armor_sold = "N/A";
} else {
 $armor_sold = explode(":", $item[$x]['armor_sold']);
 $armor_sold = implode(", ", $armor_sold);
}
}

 

 

 


Reply

Mike
Well, I know some code for MySQL that helps you list everything that is select by the query. I mean, so you don't have to use multiple queries.

You would do this:

CODE
$query=mysql_query(QUERYGOESHERE);

while($row=mysql_fetch_row($query)) echo 'WHATYOUWANTTOECHO; THE ROWS SELECT BY THE QUERY';



Here is something that I made using the SQLoops (while())

CODE
$query=mysql_query("SELECT username,realname,age,location,essay FROM mod_apps WHERE status='Approved'");

while($row=mysql_fetch_row($query)) echo '<tr ',shade(),'><td>'.$row[0].'</td><td>'.$row[1].'</td><td>'.$row[2].'</td><td>'.$row[3].'</td><td>'.$row[4].'</td></tr>';



It listed every users mod app that was in the database whos status was 'Approved'.

Reply

karlo
QUOTE(mobious @ Feb 28 2005, 08:02 PM)
remember that your shortcut method will only work if the short_open_tag config is set to true. anyways for the shortcuts that i know...

another way of writing this:

CODE
if ("red" == "red") {
print "red";
} else {
print "not red";
}


is this way...

CODE
"red" == "red" ? print "red" : print "not red";


this is the standard format:

CODE
[condition] ? [codes to bexecuted when true] : [codes to be executed when false]


for your mysql question... i have a simple loop for you. it may be simple but the product of your loop will be a multi-dimensional array. don't mind the code ok. it's just an example.

CODE
$sql = "SELECT *
FROM armor
WHERE armor_type = '{$type}'
  AND SUBSTRING(armor_name, 1, 1) LIKE '{$first_letter}'
ORDER BY armor_name ASC";

if(!($result = mysql_query($sql))) {
die(mysql_error());
}

while ($item[] = mysql_fetch_array($result, MYSQL_ASSOC));

//do the processing of data here. i always use a for.. loop.

for ($x = $start; $x < $display_item; $x++) {
if ($item[$x]['armor_sold'] == "") {
 $armor_sold = "N/A";
} else {
 $armor_sold = explode(":", $item[$x]['armor_sold']);
 $armor_sold = implode(", ", $armor_sold);
}
}

*


Please explain them to me. I can't understand it. sad.gif

Reply

FaLgoR
QUOTE
And for MySQL, I know there are many ways to retrieve the results. But how? Can you really teach me on how to use MySQL in PHP? Especially in LOOPS. I'm planning to create my own CMS. Please help me again. For my first thread, thank you all for helping me. But in this new thread, please help me!


I suggest that u tipe a look at my tutorial of an login sistem with php and mysql, there are many usefull php lines, mysql querys and looping, I'm sure, if you understand that, it will help you alot! smile.gif
Its on Tut forum (and here on php forum too, but there is alot of topics before)

Reply

FaLgoR
Here is the link:

http://www.trap17.com/forums/index.php?showtopic=7247

Hope it helps you! =)

Reply

stevey
you should really consider exploiting the object oriented features of php especially when it comes to databes and particualarly if you want to create your own cms, its usually faster and simpler to deal with objects than it is to just deal with plain variables, so such google or some php site and find a database class and you will save yourself all the hassle of having to understand databases..

Reply

mobious
that was just a simplified way to write an if..then..else.. statement.

the last part is an example of a loop to register the whole rowset into a multi-dimensional array. and then use the for loop to process the each row.

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : lot, php, questions, part, 2

  1. Questions?!
    PHP (4)
  2. Php Questions?!
    From: alex1985 (19)
    Listen, as I'm novice in PHP, I will ask certain questions in this topic hoping on your
    contribution. $dbhost='.....'; //The Database Information//
    $dbhost='localhost'; $dbname='alex1985_test';
    $dbusername='alex1985_admin'; $dbuserpass='0505009127'; //Creating
    Connection To The Database// mysql_connect ($dbhost, $dbusername, $dbuserpass);
    //Select The Certain Database// mysql_select_db ($dbname) or die ('Can Not Select
    Database'); //Start The Session// //Always Must....
  3. Gd Functions
    Questions (2)
    Hi all I want begin a new project , my new project is Photo blog ( weblog and image album ) in one
    script for example you can post many image in one post at once case . so its very good and very easy
    but we have some problems . if you can plz help me to fix this problems for example : we need
    change image size for page speed ( we dont want show 16 image in one page ) * we need GD functions
    to change image size to smaller and then show smaller image at page if you know source or tutorial
    about change image size plz post here . thankx we know we can change image size (w....
  4. Javascript To Php - A Few Questions
    (1)
    I am rewriting a Javascript into PHP, but I have two questions: How can I write these functions in
    PHP? Math.floor Math.ceil I'm sure the answer is obvious, but I really can't find it...
    /laugh.gif' border='0' style='vertical-align:middle' alt='laugh.gif' /> ....
  5. 2 Questions
    (7)
    i have 2 questions about PHP...please don't answer like "use google"...or something...because i
    tried and didn't find anything..so 1. example..i have a varible called $var and it
    contains 50 characters..so how can i write only part of them (1,2,3,20)? 2. example like the one
    before... i have a varible called $var with 50 characters..how can i write the first /second
    /third.. charachter from the $var tnx;)....
  6. Wap Forum
    several questions on WAP forums (9)
    /blink.gif' border='0' style='vertical-align:middle' alt='blink.gif' /> Right i want to set up a
    wap forum for rap battling. I think i need to use php, although i might need wml not sure. so
    questions: 1) WML or PHP? 2) Can i get a forum/message board script? 3) Where can i get it? Thanks
    in advance Not making helpful thread topics and titles results in warnings, or in extreme cases, a
    ban. Don't fall into the crack. ....
  7. A Lot Of Php Questions
    please do help me (3)
    First , i'm planning to use preg_match, ereg_match, etc.. I think "preg" and "ereg" uses
    something like in the Apache's RewriteModule the " " something like that... Do you know a
    tutorial that will easily teach me on how to do that? Second , I'm planning to use Apache
    Rewrite. But I really don't know how to use. Do you know a tutorial that will easily teach me on
    how to do that? Third , while openning some php scripts, I didn't get the meaning of example:
    CODE <?php $sample1->//some string here ?> What does it mean? I di....
  8. Html To Php Questions
    (3)
    Hi, I would like to know if it is safe to change HTML files to PHP files by just changing the
    dotHTML extension to dotPHP?? I tried it to a single html file because i used a php code of blog,
    and it worked. I'm using Internet Explore version 6 and it's working fine. I would like to
    know if the PHp files would work for other browsers after changing dotHTML to dotPHP extension.
    Thanks....

    1. Looking for lot, php, questions, part, 2

Searching Video's for lot, php, questions, part, 2
advertisement



A Lot Of Php Questions Part 2



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE