Jump to content

digibucc

Members
  • Posts

    142
  • Joined

  • Last visited

Posts posted by digibucc

  1. and sorry to keep clarifying, but it is definitely inserting empty rows - not just skipping the rest?

    and actually, what are the rest? you are pulling one session into key value pairs - where would the extra records come from?

  2. with php:

    one quick example may be to have a mysql db of possible comments, pull them into an array, and do array_rand and then print one. there are other ways to choose a random record from mysql in the first place. of course you could code the messages in an array and bypass mysql completely, but that's not the preferred way of doing it.

  3. well you have two foreach loops. .the image gets echoed for each category for each post. var _dump categories and make sure there is only one assigned to that post.

    that img code does look ok at first glance, i'd try it hardcoded with values to see if that works, then if it does check the returns of each of that $vars in it.

  4. when you say only one inserts, do you mean one key/value pair or one entire record?

     

    that insert is only inserting one record, and i only see where information for one record is being processed - more info please?

  5. Yours just takes a few more steps to complete.  Nothing really wrong with doing it that way (in the coding department), it is just more coding.  The good thing about PHP is that there is no ONE definitive way to do anything.  For instance, I only use while loops for results returned by a function, otherwise if I need to go through an array, I use a for loop.

     

    Now saying that, when posting code snippets on here, you must realize that a lot of the people that come here for help have no idea about sanitation and validation.  So always include that in your snippets.  Your code doesn't have any of that shown.  You must always escape string data in SQL, as well as make sure that data is of the proper type that you expect.

     

    Bad solution?  No, just different.

     

    thank you :) I am trying to improve my own skills and i find helping people is a great way to do that - however i don't want to give bad info. thanks again :)

  6. in his reply, $$key => $val is creating a variable (hence the first $) , with whatever name $key has from the loop, which would be the submitted session var's key

    that's where this list of variables comes from

    '$priceunit', '$product', '$qty', '$id', '$price', '$month', '$day', '$year', '$academy', '$date'

  7. for $picture to be empty and

     

    $picture[/size][/color]->[/size][/color]getElementsByTagName[/size][/color]([/size][/color]'url'[/size][/color])->[/size][/color]item[/size][/color]([/size][/color]0[/size][/color])->[/size][/color]nodeValue

    to have results, something is wrong, did you try the var_dump in the same exact place?

     

     

    $picture should be an object, not an array - why are you trying to make it an array?

    you said you get results, but what. what var dump says specifically is very useful in debugging why your echo isn't working. maybe it's an object or something?

     

     

    so copy paste the exact result of the var dump of [/size][/color]$picture[/size][/color]->[/size][/color]getElementsByTagName[/size][/color]([/size][/color]'url'[/size][/color])->[/size][/color]item[/size][/color]([/size][/color]0[/size][/color])->[/size][/color]nodeValue

  8. so you'd take that $temp variable

    and then :

     
    <?php
    echo '<img src="images/degrees/'.  str_replace(chr(176), '',  $temp). '.jpg" alt="'. $temp. '">';
    ?>
    

     

    or if it's an html page mostly

     

     

     
    <img src="images/degrees/<?php echo str_replace(chr(176), '', $temp). '.jpg" alt="'. $temp; ?> ">
    

     

    and then just have an images/degrees/ folder with 20.jpg, 21.jpg, etc in it. or whatever format you need, just change the extension in the code.

     

     

    rereading just do a str_replace, taking out the degree symbol, and then name the images 20C.jpg, etc. i updated the code above to reflect that.

  9. var dump your object to make sure it's set and the structure is what you are using

     

    <?php var_dump($picture->getElementsByTagName('url')->item(0)->nodeValue);?>

    and see if it has anything.

     

    if not,

    <?php var_dump($picture); ?>

     

    if it's empty, you have a deeper problem, if it's not empty, you're not following the children properly, so just go one by one until you find the mistake.

  10. an api is an "Application Programming Interface", which means it's an interface you can use to get data from them when building applications.

     

    we need more info about their api, but in general, you will use their method of requesting info, usually post - and they will return an xml file that can be parsed by simplexml for example, and using that you can output the received info or do what you need.

     

    edit: looking at their api page this is the case.

    you would need to construct a link that looks like this

     

    the color in red is the command you want to run, change it

     

    you'll need to do that in php obviously , to be able to do anything with the info, otherwise it will just show an xml page

     

    i did something similar for another site

     

    <?php
    $url = "http://api.jambase.com/search";
    				$url .= '?band='. str_replace("\\", "", str_replace( ' ', '+', $data["band"]));
    				if (!empty($data["zip"])){$url .= '&zip='. $data["zip"];}
    				if (!empty($data["radius"])){$url .= '&radius='. $data['radius'];}
    				$url .= '&apikey=xxxxxxxxxxxxxxxxx';
    				//echo $url. '<br>';
    
    				// Load the call and capture the XML document returned by API as an object
    				$xml = simplexml_load_file($url);
    ?>

     

    and it will then return an xml object to the $xml variable

     

    read the http://php.net/manual/en/book.simplexml.phpsimplexml man page to know how to do what you want with the retrieved info

     

     

  11. i'd disagree - maybe.

     

    how much time do you have? do you have ANY interest in learning this or just want it done. do you HAVE the money to pay someone to do it for you?

     

    if you can make a proper html and css page, and you have a server than execute php all ready to use, there are many snippet resources to just add a small amount of interaction or make the site basically dynamic.

     

    http://www.hotscripts.com/

    http://www.scripts.com/php-scripts/

    http://www.opensourcescripts.com/dir/php.html

    are just a few quick examples, from a google search.

     

    if you have some cash, and don't want to do it yourself at all - pay someone. but if you don't mind learning a few basics and tinkering with some cut and paste code, that isn't to hard honestly.

     

    i started out using copy paste code to get what i needed, then i learned how to change that code - then i learned how to write my own. it all depends on what you WANT to do

  12. your way is interesting, similar to mine but not quite, what do you think of mine (obviously without your checks, as this wasn't meant to be live just an example):

     

    <?php
    
    foreach ($_POST as $key=>$value){
    if ($value != '' && $value != 'Submit'){
    $cols .= mysql_real_escape_string($key). ', ';
    $vals .= '\''. mysql_real_escape_string($value). '\', ';
    }
    }
    
    $columns = substr($cols,0,-2); // trim trailing "'," , 
    $values = substr($vals,0,-2);
    
    $sql="INSERT INTO table ( $columns )VALUES ( $values )";
    ?>

     

    just curious. i like to compare my solutions with others, as there is always a better way to do the things we do ;)

  13. jcbones if i could ask, how does that compare to this:

     

    <?php
    $sets = count($_POST) / 2;
    $x = 0;
    $sql = "INSERT INTO Persons (FirstName,Age) VALUES";
    while ($sets > 0){
    $sql .= '('. $_POST['FirstName'. $x]. ','. '('. $_POST['Age'. $x]. '),';
    $sets --;
    $x++;
    }
    $sql= substr($sql,0,-1); // trim trailing ","
    ?>

     

    i know mine's messy and your's is cleaner, but that's why i'm asking. i am looking for a better understanding of your code vs mine. functionally how different are they? is mine a bad solution or is yours just a better one? thank you :)

  14. the reason these standards are important even though codes could work otherwise, is the same reason php is generally viewed with disdain as being to messy and having to low a barrier to entry. It's really easy to write out a piece of code with any understanding of syntax or functions, arrays, etc. it's more possible to hack your way through than other languages. but the honest truth is with a proper understanding it's one of the most flexible and useful codebases out there, and if you follow the new standards it's very impressive.

     

    it's good for EVERYONE that uses php, for EVERYONE that uses php to use standards, because standards make things smoother and also allow for systematic improvement.

     

    so don't get hard on yourself about the code not being to standard, that takes longer to learn and remember. just keep trying and you'll learn bits as you go. it really is very fun if you can stop yourself from getting stressed.  with a good enough understanding you'll actually ENJOY these debugging activities.

     

    good luck :)

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.