PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rating: Thread Rating: 10 votes, 4.50 average. Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #31  
Old June 22nd, 2003, 08:27 PM
esha esha is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Location: USA
Posts: 17 esha User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
What should I do if I am getting this fatal error:Fatal error: Cannot redeclare <bold>somefunction()</bold> (previously declared in \somewhere\filename.php:line x) in \somewhere\filename.php:line x?

It means you have the same include file in two places.
for example let us say you have a file name index.php

and in index.php:
<php>
include("file1.php");
include("file2.php");
</php>
and then let us say in file1.php:
<php>
include("file2.php");
</php>
then you will get this fatal error. all you need to do is comment out include file2.php inside file1.

Reply With Quote
  #32  
Old August 5th, 2003, 10:45 AM
drgroove's Avatar
drgroove drgroove is offline
pushing envelopes, not pencils
Dev Shed God 2nd Plane (6000 - 6499 posts)
 
Join Date: Feb 2002
Posts: 6,223 drgroove User rank is First Lieutenant (10000 - 20000 Reputation Level)drgroove User rank is First Lieutenant (10000 - 20000 Reputation Level)drgroove User rank is First Lieutenant (10000 - 20000 Reputation Level)drgroove User rank is First Lieutenant (10000 - 20000 Reputation Level)drgroove User rank is First Lieutenant (10000 - 20000 Reputation Level)drgroove User rank is First Lieutenant (10000 - 20000 Reputation Level)drgroove User rank is First Lieutenant (10000 - 20000 Reputation Level)drgroove User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Day 4 h 32 m 57 sec
Reputation Power: 174
Quote:
Originally posted by AlCapone
#24 How do I make prev/next links?

General code would be something like this:
PHP Code:
 mysql_connect('localhost') or die('cant connect');;#,'user','pass');
mysql_select_db('one');


$perPage=1;
$start=isset($HTTP_GET_VARS['s'])?$HTTP_GET_VARS['s']:0;
$total_rows=isset($HTTP_GET_VARS['t'])?$HTTP_GET_VARS['t']:'';
$PHP_SELF=isset($HTTP_SERVER_VARS['PHP_SELF'])?$HTTP_SERVER_VARS['PHP_SELF']:'';

if(!
$total_rows)
    list(
$total_rows)=mysql_fetch_row(mysql_query('select count(*) from user'));

$result=mysql_query("select * from user limit $start,$perPage");

while (
$data=mysql_fetch_assoc($result)) 
    echo 
$data['username'];//output data here

$startP=$start-$perPage;
echo 
$startP>=0"<a href='$PHP_SELF?t=$total_rows&s=$startP'>PREV</a>  " 'PREV  ';

$startN=$start+$perPage;
echo 
$startN<$total_rows "<a href='$PHP_SELF?t=$total_rows&s=$startN'>NEXT</a>  " 'NEXT  ';?> 

Several things you need to be aware of:
Firstly, as you see I've decided to pass total # of records through url in sake of saving some time and load for mysql and not requesting to count rows every time. I do not think this could cause any problems, but it surely will take the load off of sql db.

And secondly, you can as well make it work through POST so that none of the variables show up in the URI, but it is up to you to decide which is *the way*, personally I dont see any advantages of one over another. Good luck reaching max url size with just search keywords.

edited for better code


Joao Prado Maia posted code on O'Reilly which also accomplishes this task - as this is easily one of the most asked questions, I thought to post a link to his PHP class for this functionality, as an addendum to AlCapone's own code.

PHP Pagination Class

Its fairly straightforward to implement and highly portable - JPM also allows use of this free of charge.
__________________
Give a person code, and they'll hack for a day; Teach them how to code, and they'll hack forever.
Analyze twice; hack once.
The world's first existential ITIL question: If a change is released into production without a ticket to track it,
was it actually released?


About DrGroove: ITIL-Certified IT Process Engineer - Enterprise Application Architect -
Freelance IT Journalist - Devshed Moderator - Funk Bassist Extraordinaire


Reply With Quote
  #33  
Old September 19th, 2003, 02:34 AM
paCkeTroUTer paCkeTroUTer is offline
Gone PHP Crazy
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Location: Melbourne, Australia
Posts: 393 paCkeTroUTer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 m 33 sec
Reputation Power: 6
Send a message via ICQ to paCkeTroUTer
How to Populate a Multiple Select Option Box from the Database

#39 How to Populate a Multiple Select Option Box from the Database

This is an example of how to populate a Multi-Select Option Box from the database. A few times it has been asked in the forum but not been given a complete example. Hope this helps someone.
PHP Code:
<?php
    
// Connect to Database ###########################################################
        
require ('norka.php');
    
// Connect to Database ###########################################################
    
    
echo "<select name=\"select_products[]\"  size=\"5\" style=\"width: 160px;\" multiple >";
    
    
//query for All the products                                
    
$get_all_pdts "Select id, pdt_name from norka_products where pdt_status = '1'";
    
$exe_get_all_pdts mysql_query($get_all_pdts);

    
//query for the Products to be selected  ## Change per your requirements ##
    
$get_selected_pdts "SELECT norka_gallery_products.pdt_id 
                FROM norka_gallery_products, norka_gallery_pics 
                WHERE norka_gallery_products.pic_id = norka_gallery_pics.pic_id 
                and norka_gallery_pics.image_link ='" 
"gallery/car_wash.jpg" "'";                            
    
$exe_get_selected_pdts mysql_query($get_selected_pdts);
    
    while(
$selected_pdts mysql_fetch_array($exe_get_selected_pdts))
    {
        
//Get the values which need to be selected into an array
        
$selected_array[] = $selected_pdts['pdt_id'];
    }
            
    while(
$all_pdts mysql_fetch_array($exe_get_all_pdts)) //All the records
    
{
        
$value $all_pdts['id'];
        
$name $all_pdts['pdt_name'];
        if(
sizeof($selected_array) > 0)
        {
            if (
in_array($value$selected_array)) 
            { 
                print 
"<option value=\"$value\" selected>" $name "</option>\n";                
            } 
            else 
            { 
                print 
"<option value=\"$value\">" $name "</option>\n";                 
            } 
        }
        else
        {
            print 
"<option value=\"$value\">" $name "</option>\n";  
        }
    }
        
    
mysql_free_result($exe_get_all_pdts);
    
mysql_free_result($exe_get_selected_pdts);
    echo 
"</select>";
?>
__________________
visit http://www.techsatcomputers.com

Reply With Quote
  #34  
Old November 26th, 2003, 01:46 PM
melsana's Avatar
melsana melsana is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: MD
Posts: 373 melsana User rank is Corporal (100 - 500 Reputation Level)melsana User rank is Corporal (100 - 500 Reputation Level)melsana User rank is Corporal (100 - 500 Reputation Level)melsana User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via AIM to melsana
Quote:
Originally posted by Sepodati
#20. Should I use echo or print?
Doesn't matter, they are the same.

I find it very useful to use one for my main output and the other for my debug statments that way I can easily search for debug statements and comment them out or use them.
Comments on this post
dotancohen agrees: good idea

Reply With Quote
  #35  
Old January 27th, 2004, 11:17 PM
codergeek42's Avatar
codergeek42 codergeek42 is offline
Language Nerd
Dev Shed God 2nd Plane (6000 - 6499 posts)
 
Join Date: Jul 2003
Location: Anaheim, CA (USA)
Posts: 6,388 codergeek42 User rank is Lieutenant General (80000 - 90000 Reputation Level)codergeek42 User rank is Lieutenant General (80000 - 90000 Reputation Level)codergeek42 User rank is Lieutenant General (80000 - 90000 Reputation Level)codergeek42 User rank is Lieutenant General (80000 - 90000 Reputation Level)codergeek42 User rank is Lieutenant General (80000 - 90000 Reputation Level)codergeek42 User rank is Lieutenant General (80000 - 90000 Reputation Level)codergeek42 User rank is Lieutenant General (80000 - 90000 Reputation Level)codergeek42 User rank is Lieutenant General (80000 - 90000 Reputation Level)codergeek42 User rank is Lieutenant General (80000 - 90000 Reputation Level)codergeek42 User rank is Lieutenant General (80000 - 90000 Reputation Level)codergeek42 User rank is Lieutenant General (80000 - 90000 Reputation Level)codergeek42 User rank is Lieutenant General (80000 - 90000 Reputation Level)codergeek42 User rank is Lieutenant General (80000 - 90000 Reputation Level)codergeek42 User rank is Lieutenant General (80000 - 90000 Reputation Level)codergeek42 User rank is Lieutenant General (80000 - 90000 Reputation Level)  Folding Points: 35702 Folding Title: Starter FolderFolding Points: 35702 Folding Title: Starter Folder
Time spent in forums: 1 Month 1 Week 5 Days 17 h 4 m 7 sec
Reputation Power: 886
Send a message via ICQ to codergeek42 Send a message via AIM to codergeek42 Send a message via Yahoo to codergeek42 Send a message via Google Talk to codergeek42
I find melsana's idea of differentiating between the two for normal/debug output hepful, because I use echo for everything normally and print for all my debug output, so in my IDE, i can just do a search and replace all occurences of "print(" with "//print(" to comment all debug statements. It makes my coding easier to do search-replacing.

Good post.

Reply With Quote
  #36  
Old February 23rd, 2004, 05:50 PM
moejoe moejoe is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 1 moejoe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
CHmod in win2k?

Hi, how do i set CHmod (FIle Permissions) on Windows 2000 with APache 2/PHP and mysgl install on my personal webserver as i cant do it from my ftp client as its fro unix only if i cant do it in windows 2000, i might hav to change my server OS to linux

cheers

moe

Reply With Quote
  #37  
Old February 24th, 2004, 01:12 PM
scoutt's Avatar
scoutt scoutt is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2001
Posts: 645 scoutt Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 16 sec
Reputation Power: 0
this is a FAQ, not a thread to ask questions.

but to answer you, you can't chmod files in windows. you don't need to.
Comments on this post
helloakash disagrees: There is attrib command. And we need to change permissions sometimes
__________________
Snippet Library

Reply With Quote
  #38  
Old April 6th, 2004, 03:31 PM
saintp saintp is offline
Hoopy Frood
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 370 saintp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 44 m 54 sec
Reputation Power: 5
#40. I put some text into a database, and when I pull it out all the newlines are gone! Ack!

A: No, they aren't. HTML treats newlines as generic whitespace. If you view your source, they're still there. Luckily, PHP provides a handy function, nl2br() that lets you convert newlines to HTML linebreak tags.
__________________
RTFM | LLPM | LIMC | LVKK

Reply With Quote
  #39  
Old April 6th, 2004, 04:01 PM
Sepodati's Avatar
Sepodati Sepodati is offline
Banned
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Dec 1999
Location: Afghanistan
Posts: 14,360 Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)  Folding Points: 69546 Folding Title: Intermediate FolderFolding Points: 69546 Folding Title: Intermediate FolderFolding Points: 69546 Folding Title: Intermediate FolderFolding Points: 69546 Folding Title: Intermediate Folder
Time spent in forums: 2 Months 3 Weeks 6 Days 2 h 26 m 30 sec
Reputation Power: 1606
Send a message via ICQ to Sepodati Send a message via Yahoo to Sepodati
Quote:
Originally Posted by saintp
PHP provides a handy function, nl2br() that lets you convert newlines to HTML linebreak tags.
PHP actually just adds in the <br /> tag and doesn't "convert" the newlines; they're still there. Just so everyone's on the same page.

---John Holmes...

Reply With Quote
  #40  
Old April 20th, 2004, 04:01 PM
saintp saintp is offline
Hoopy Frood
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 370 saintp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 44 m 54 sec
Reputation Power: 5
#41. How do I make a select list/drop down menu autopopulate depending on the value of another select list?

This one must come up three times a day.

Here is real code that I have used to great success; this snippet comes from a system that lets students in some of our chemistry courses do their labs via a PHP app. This snippet is from the administrative-side "edit a lab" script. I've tried to remove all custom functions

PHP Code:
//************** start dynamic drop-down list magic ***************// 
  
print "<script language=\"javascript\"><!--\n"
  
$classes mysql_query("SELECT class FROM classes ORDER BY class"); 
  print 
"var labIDs = new Array(" mysql_num_rows($classes) . ");\n"
  print 
"var labNames = new Array(" mysql_num_rows($classes) . ");\n"
  while (list(
$class) = mysql_fetch_array($classes)) { 
     
$labs mysql_query("SELECT DISTINCT labID FROM duedates WHERE class = $class ORDER BY due"); 
     print 
"labIDs[$class] = new Array(" . (sizeof($labs) + 1) . ");\n"
     print 
"labNames[$class] = new Array(" . (sizeof($labs) + 1) . ");\n"
     
$i 1
     print 
"labIDs[$class][0] = 0;\n"
     print 
"labNames[$class][0] = 0;\n"
     while (list(
$lab) = mysql_fetch_array($labs)) { 
        print 
"labIDs[$class][$i] = '$lab';\n"
        print 
"labNames[$class][" $i++ . "] = '"
        print 
addslashes(mysql_result(mysql_query("SELECT name FROM labs WHERE class = $class AND labID = $lab"), 1)); 
        print 
"';\n"
     } 
  } 
  print <<<
EOJS 
function clean(what) { 
  for (; 
what.options.length 1;) { 
     
what.options[what.options.length 1] = null
  } 


function 
updateLabs(which) { 
  
with (document.forms[0]) { 
     
clean(which); 
     
curClass course.options[course.selectedIndex].value
     for (var 
1labIDs[curClass].lengthi++) { 
       
which.options[which.options.length] = new Option(labIDs[curClass][i] + ". " labNames[curClass][i], labIDs[curClass][i]); 
     } 
  } 

//--></script> 
EOJS;  //************** end dynamic drop-down list magic ***************// 

  
print form_open(); 
  
//replace the old static drop-down tag with a new dynamic one 
  
print "Course: <select name=\"course\" onChange=\"javascript: updateLabs(lab);\">\n";
  
$classes mysql_query("SELECT class FROM classes ORDER BY class")
  print 
"<option value=0 selected>Choose one:</option>\n";
  while (list(
$class) = mysql_fetch_assoc($classes)) {
    print 
"<option value=$class>$class</option>\n"