NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page whats wrong here? [php]

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search
5 members in live chat ~  


Closed Thread
 
LinkBack Thread Tools
Old 01-14-2007, 02:10 AM THREAD STARTER               #1 (permalink)
Senior Member
Join Date: May 2005
Location: Ontario Canada
Posts: 3,088
unknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to behold
 


Diabetes

whats wrong here? [php]


hey
i am not getting an error..it just doesnt show anything when it should

PHP Code:
        function loadMedia($limit,$cid=-1)
????: NamePros.com http://www.namepros.com/programming/281056-whats-wrong-here-php.html
        {
        
$media = array();
        if (
$cid == -1) {
        
$where "WHERE `status` = 1"; }
        
$q "SELECT * FROM `media` $where order by `timestamp` desc LIMIT 0,$limit";
        
$result $this->query($q);
        for (
$b 0$b <(mysql_num_rows($result));$b++)
        {
            
$db mysql_fetch_array($result);
????: NamePros.com http://www.namepros.com/showthread.php?t=281056
            
$media[$b] = array($db['id'],$db['cat_id'],$db['by_id'],$db['file_name'],$db['dp'],$db['title'],
                        
$db['description'],$db['views'],$db['timestamp']);
        }
        return 
$media or die ("cant");;
        } 
and then :
PHP Code:
<?$media $database->loadMedia(1); echo$media['0']['5'];?>
unknowngiver is offline  
Old 01-14-2007, 05:34 AM   #2 (permalink)
Senior Member
 
Shorty's Avatar
Join Date: Sep 2005
Location: England
Posts: 1,034
Shorty is just really niceShorty is just really niceShorty is just really niceShorty is just really nice
 



It sounds like $cid != -1.

Either do "$cid = -1" before you call the function, or do it after $media = array();.
Shorty is offline  
Old 01-14-2007, 05:44 AM   #3 (permalink)
Senior Member
Join Date: Dec 2006
Location: England
Posts: 1,565
Matthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud of
 


Adoption Breast Cancer Breast Cancer Cancer Survivorship
EDIT:
I didn't notice before.

Change:
PHP Code:
return $media or die ("cant");; 
To:
PHP Code:
return $media
????: NamePros.com http://www.namepros.com/showthread.php?t=281056
That should fix it. With the 'or die' currently in the function, it will not be returning the array.


Possible Shorty but since he did not supply the second argument when using the function it should have been -1 by default. By it could be

Run this:
PHP Code:
echo '<pre>';
print_r$media )
echo 
'</pre>'
To see if the array is populated.

As a side note it does not matter in this case however you do not use '' for numerical array keys.
Last edited by Matthew.; 01-14-2007 at 05:51 AM.
Matthew. is offline  
Old 01-14-2007, 10:00 AM   #4 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
Join Date: Feb 2006
Posts: 2,792
Dan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant future
 


Autism Autism Autism Autism Autism Autism Autism
You should have had an error for an unexpected semi colon, too. When you are trying to find what's wrong, use error_reporting(E_ALL);
Dan is offline  
Old 01-14-2007, 10:07 AM   #5 (permalink)
Senior Member
Join Date: Dec 2006
Location: England
Posts: 1,565
Matthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud of
 


Adoption Breast Cancer Breast Cancer Cancer Survivorship
Originally Posted by Dan
You should have had an error for an unexpected semi colon, too. When you are trying to find what's wrong, use error_reporting(E_ALL);
The extra semi colon wasn't the problem. (although could well have been in other cases)

I tried a little experiment since i didn't know 100% if it was the problem but:

PHP Code:
function test($test
{
    
$string 'hi';
    
    if(
$test == true)
    {
        return 
$string or die('cant');
    }
    else
    {
        return 
$string;
    }

PHP Code:
echo test(false);
// will output "hi"

echo test(true);
// will output "1" 
Unsure as to why but adding the or die seems to return 1.
Matthew. is offline  
Old 01-14-2007, 10:18 AM   #6 (permalink)
Senior Member
 
ahtum's Avatar
Join Date: May 2006
Posts: 1,327
ahtum has much to be proud ofahtum has much to be proud ofahtum has much to be proud ofahtum has much to be proud ofahtum has much to be proud ofahtum has much to be proud ofahtum has much to be proud ofahtum has much to be proud ofahtum has much to be proud ofahtum has much to be proud of
 


Ethan Allen Fund Find Marrow Donors!
Here i rewrote a little your code.

Hope it works

If it's not working then you might have problems with your the mysql class that you are using.
????: NamePros.com http://www.namepros.com/showthread.php?t=281056

PHP Code:
function loadMedia $limit $cid '-1' ){
    
    
$media = array();
    
    if (
$cid == '-1'){
        
$where "WHERE `status` = 1";
????: NamePros.com http://www.namepros.com/showthread.php?t=281056
    }else{
        
$where "";
    }
    
    
$q "SELECT * FROM `media` $where order by `timestamp` desc LIMIT 0,$limit";
    
$result $this->query($q);
    
    
$db mysql_fetch_array($result);
    
    for (
$b 0$b <(mysql_num_rows($result));$b++){
            
        
$media[$b] = array    (    $db['id'],$db['cat_id'],$db['by_id'],$db['file_name'],$db['dp'],
                                
$db['title'],$db['description'],$db['views'],$db['timestamp']
                            );
    }
    
    return 
$media;

ahtum is offline  
Old 01-14-2007, 10:20 AM   #7 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
Join Date: Feb 2006
Posts: 2,792
Dan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant future
 


Autism Autism Autism Autism Autism Autism Autism
If you change

if($test == true)
to
if($test === true)

it will run just return $string;

I can't figure out why it makes it return 1..
"void exit ( [string status] )"



Ahtum, you need to have it get the row inside of the for loop to get all of the rows. What you did would only get one.
Dan is offline  
Old 01-14-2007, 10:23 AM   #8 (permalink)
Senior Member
Join Date: Dec 2006
Location: England
Posts: 1,565
Matthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud of
 


Adoption Breast Cancer Breast Cancer Cancer Survivorship
Originally Posted by Dan
If you change

if($test == true)
to
if($test === true)

it will run just return $string;
No it wont?
Matthew. is offline  
Old 01-14-2007, 10:25 AM   #9 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
Join Date: Feb 2006
Posts: 2,792
Dan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant future
 


Autism Autism Autism Autism Autism Autism Autism
Originally Posted by Matthew.
No it wont?
... not if you use true... He's not using true as the input, so your test doesn't necessarily do anything except for showing that it's weird how it returns 1.
Dan is offline  
Old 01-14-2007, 10:30 AM   #10 (permalink)
Senior Member
Join Date: Dec 2006
Location: England
Posts: 1,565
Matthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud of
 


Adoption Breast Cancer Breast Cancer Cancer Survivorship
Originally Posted by Dan
... not if you use true... He's not using true as the input, so your test doesn't necessarily do anything except for showing that it's weird how it returns 1.
Which was the aim of my test The conditional is irrelevant, it was just to make it easier to swap between the 2 (I'm bored gimme a break.)
????: NamePros.com http://www.namepros.com/showthread.php?t=281056

PHP Code:
function test($string
{
    return 
$string or die("cant");




I'm determined to find out why it returns 1...
Matthew. is offline  
Old 01-14-2007, 12:21 PM   #11 (permalink)
Professional Monkey
 
Amnezia's Avatar
Join Date: Jul 2005
Location: Escaped from the zoo
Posts: 907
Amnezia has a spectacular aura aboutAmnezia has a spectacular aura about
 


Cancer Survivorship Save a Life
Originally Posted by Matthew.
Which was the aim of my test The conditional is irrelevant, it was just to make it easier to swap between the 2 (I'm bored gimme a break.)
????: NamePros.com http://www.namepros.com/showthread.php?t=281056

PHP Code:
function test($string
{
    return 
$string or die("cant");




I'm determined to find out why it returns 1...
return is a langauge construct not a function therefore it does not return an exit code.

in other words

return $somestring or die("some message") is a pointless line of code
__________________
Webmaster Words
Amnezia is offline  
Old 01-14-2007, 12:41 PM   #12 (permalink)
Senior Member
Join Date: Dec 2006
Location: England
Posts: 1,565
Matthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud of
 


Adoption Breast Cancer Breast Cancer Cancer Survivorship
Originally Posted by Amnezia
return is a langauge construct not a function therefore it does not return an exit code.
????: NamePros.com http://www.namepros.com/showthread.php?t=281056

in other words

return $somestring or die("some message") is a pointless line of code
That i know (which is why i said remove it from the original code)

My point/query was why it returns 1 It is not important, merely something i was wondering
Matthew. is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


 
All times are GMT -7. The time now is 02:19 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger