Jump to content

Canman2005

Members
  • Posts

    669
  • Joined

  • Last visited

    Never

Posts posted by Canman2005

  1. Hi all

    Is there a way to do two if statements? Currently I use

    [code]<? if ("".$_POST['gender']."" == 'male') { print "male"; }?>[/code]

    Can a sql statement be written to something like below

    [code]<? if ("".$_POST['gender']."" == 'male' & "".$_POST['age']."" == '11') { print "male"; }?>[/code]

    So as well as checking the gender, I can also check the age?

    Thanks in advance

    Ed
  2. [!--quoteo(post=354503:date=Mar 13 2006, 02:36 PM:name=fusionpixel)--][div class=\'quotetop\']QUOTE(fusionpixel @ Mar 13 2006, 02:36 PM) [snapback]354503[/snapback][/div][div class=\'quotemain\'][!--quotec--]
    Yes you can, what you need to do is pass the variable from the drop down to the new page so it looks like this:

    newpage.html?yourvariable=200

    then in the same page you use php to get the variable:

    <span class='total'><? echo $_GET['yourvariable'];?> </span>
    [/quote]
    Thanks, worked great
  3. Dear all

    I have a piece of javascript on my site which produces a value from a drop down list, if you select number 234 from the drop down, then it dynamically prints 234 on screen, it prints the value in between the tag

    <span id="total"></span>

    Is there anyway you can use php to add to the number which is printed on screen? Something like

    <span id="total"><?php echo +200 ?></span>

    I tried a few things but cant seem to get it to do what I want, thought I should ask here before I spend the week rewriting the script.

    Thanks

    Ed
  4. Worked it out, if anyone is interested I passed

    $_SESSION['nextid'] = mysql_insert_id();

    with my php page action and then called the session name ($_SESSION['nextid']) on the next page.

    Thanks anyone who helped

    Ed
  5. Dear all

    I have a php insert query to insert some form data. Once the form has been submitted and the data added to the sql database, is there anyway to bring the auto increase ID number which is generated in the sql database?

    Any help would be great.

    Thanks

    Ed
  6. [!--quoteo(post=352251:date=Mar 6 2006, 09:52 PM:name=Gaia)--][div class=\'quotetop\']QUOTE(Gaia @ Mar 6 2006, 09:52 PM) [snapback]352251[/snapback][/div][div class=\'quotemain\'][!--quotec--]
    Where are you getting the value of $action from?
    [/quote]


    Via the form, so the form action might look like

    <form id="form" method="post" action="page.php?action=delete">
  7. Hi all

    Has anyone ever run into problems using the action query such as

    [code]if ($action == "delete" && $id != "")
    {[/code]

    For some reason the web server I am using doesnt understand what the action is and simply ignores it, executing the first sql statement it can find on the page.

    Any ideas would be great.

    Thanks

    Ed

  8. Hi all

    I have a php result page which currently displays results one after each other, like

    result 1
    result 2
    result 3
    result 4

    I use a very simple php query, which is

    [code]<?
    session_start();
    include ("db.php");
    $sql ="SELECT * FROM files";

    $result = @mysql_query($sql,$connection) or die(mysql_error());
    ?>[/code]

    followed by the code for results

    [code]<?
    while ($rows = mysql_fetch_array($result)) {
    ?>
    <? print "$rows[name]"; ?><br>
    <?
    }
    ?>[/code]

    How can I get results to appear in a 4 column wide table, the code for the table would look like

    [code]<table>
      <tr>
        <td>result 1</td>
        <td>result 2 </td>
        <td>result 3 </td>
        <td>result 4 </td>
      </tr>
      <tr>
        <td>result 5 </td>
        <td>result 6 </td>
        <td>result 7 </td>
        <td>result 8 </td>
      </tr>
    </table>[/code]

    rather than appearing one after each other? Is that easy?

    Loads of thanks in advance

    Dave
  9. Dear all

    I have a simple sql statement which adds up all the numbers in one colum of my database, the code I used is

    [code]$sql ="SELECT SUM(cost) as 'cost' FROM results WHERE resultid = '$resultid'";
    $sql = @mysql_query($total,$connection) or die(mysql_error());[/code]

    As well as the colum "cost" I also have another colum in my database called "costtwo"

    How can I get the statement to add these two coloums (cost + costtwo) and then total the rows up? Basically like it does now, but adding costtwo before it tots up the rest of the values

    Is this easy?

    Thanks

    Dave
  10. [!--quoteo(post=351603:date=Mar 4 2006, 03:38 PM:name=michaellunsford)--][div class=\'quotetop\']QUOTE(michaellunsford @ Mar 4 2006, 03:38 PM) [snapback]351603[/snapback][/div][div class=\'quotemain\'][!--quotec--]
    I wrote this little script to display the contents of a directory on a server with directory listings turned off. Maybe it will be useful.

    [code]    $dir = realpath("documents");
        if (is_dir($dir)) {
            if($dh=opendir($dir)) {
                while(($file=readdir($dh))!=false) {
                    if(substr($file,0,1)!=".") {
                        $file_array[$i++]=$file;
                    }
                }
                closedir($dh);
            }
        }
        array_multisort($file_array,SORT_ASC,SORT_STRING);
        reset($file_array);
        echo "<table>";
        do {
            if(current($file_array)!="") {
            echo "<tr><td>".current($file_array);
            echo "<td>".date("m/d/Y h:i a",filemtime("documents/".current($file_array)))."&nbsp;&nbsp;&nbsp;";
            echo "<td>";
            echo number_format(round(filesize("documents/".current($file_array)),1024));
            echo "k</tr>\n";
            }
        } while(each($file_array));
    [/code]
    file_exists just checks to see if a file exists, true if so, false if not.

    so the link would just be something like "<a href=\"".$num['filename'].$type."\">";

    you can get type tweaking the previous code:
    [code]if(file_exists($num['filename'].".pdf")) $type=".pdf";
    if(file_exists($num['filename'].".doc")) $type=".doc";
    if(file_exists($num['filename'].".xls")) $type=".xls"; [/code]

    or if it's tucked in directory:
    [code]if(file_exists("documents/".$num['filename'].".pdf")) $type=".pdf";[/code]
    [/quote]

    Thanks for all the info.

    When I try and use your script I get


    Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in c:\wamp\test.php on line 13

    Warning: reset() [function.reset]: Passed variable is not an array or object in c:\wamp\test.php on line 14

    Warning: current() [function.current]: Passed variable is not an array or object in c:\wamp\test.php on line 17

    Warning: Variable passed to each() is not an array or object in c:\wamp\test.php on line 24


    Any ideas?

    Thanks

    Ed
  11. [!--quoteo(post=351601:date=Mar 4 2006, 03:24 PM:name=michaellunsford)--][div class=\'quotetop\']QUOTE(michaellunsford @ Mar 4 2006, 03:24 PM) [snapback]351601[/snapback][/div][div class=\'quotemain\'][!--quotec--]
    I have two things you can try... the second will take a while to dig up... but have you thought about just using file_exists?

    if(file_exists($myrow['filename'].".pdf")) ...
    if(file_exists($myrow['filename'].".doc")) ...
    if(file_exists($myrow['filename'].".xls")) ...
    [/quote]

    Thanks for that.

    I have never used file_exists before, could you explain how I could query with that?

    Thanks

    Ed
  12. Dear all

    I have a question and im wondering if someone can help with a solution.

    Basically I have a bunch of files, they are word, excel and pdf documents, I also have a sql database which holds the first part of all these files, the database does not hold the exension of each file as it could be one of 3 filetypes.

    For example I have 1 file called

    helpme.pdf

    in the database im simply holding the first part of the file, for the above example I hold in the sql database

    helpme

    I don't hold the extension of each file as it could be one of 3 file types

    .doc - for word documents
    .xls - for exel documents
    .pdf - for pdf documents

    So there is no point in putting helpme.pdf as the file could be a word document (.doc) or a excel (.xls) document.

    I then have a php page which performs a query and returns the list of files stored in the sql database, the sql I use is

    [code]
    <?
    session_start();
    include ("connect.php");
    $sql ="SELECT * FROM files WHERE file = $file";

    $result = @mysql_query($sql,$connection) or die(mysql_error());
    $num = mysql_num_rows($result);

    ?>[/code]

    I then print off the filenames using

    [code]<?php print "$rows[file]"; ?>[/code]

    so a result page looks kind of like

    helpme
    guide
    workflow
    book

    What I want to do is to put a link next to each result to link to the file, so it looks like

    helpme - link to file
    guide - link to file
    workflow - link to file
    book - link to file

    as the database does not know what the file extension is, can I php statement be written which checks a specified folder (which the files are stored in) and then check to see if there is file matching the result which ends in either

    .doc
    .xls
    .pdf

    There will never be more then one file with the same name, ie. there is not a

    helpme.pdf
    helpme.xls
    helpme.doc

    there is only ever one file with the same name. The sql statement would need to find the file which just matches the first part of the filename.

    Does that make any kind of sense to anyone? Can anyone help me?

    Thanks in advance

    Ed
  13. Hi all

    I have a simple script which produces a code for me on the homepage, the php I use is

    [code]srand(time());
    $rand1 = (rand()%99999);
    $rand2 = chr(rand(ord("a"), ord("z")));
    $date = date("dmY");
    $code = "$rand1$rand2$date";[/code]

    I then print the code using

    [code]<?php print "$code"; ?>[/code]

    How can I retain this code and print it on any page that the user goes to? Even if they return to the homepage, how can I keep the code without it being replaced with a new one?

    How could I also create a page to delete the code so the user can get a new code when they return to the homepage.

    Any help would be great

    Thanks in advance everyone

    Ed
  14. [!--quoteo(post=350049:date=Feb 27 2006, 11:23 PM:name=Canman2005)--][div class=\'quotetop\']QUOTE(Canman2005 @ Feb 27 2006, 11:23 PM) [snapback]350049[/snapback][/div][div class=\'quotemain\'][!--quotec--]
    Hello

    thanks for that, it worked great. I have another question about the same form and php page.

    How could we get the sql statement to return all rows which contain the first 3 numbers of whatever has been selected from the drop down list?

    So if 1990 is selected from the drop down on the form, it would return all rows which have 199 in the date column, so 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 as they all start with 199

    Any help would be great

    Thanks

    Dave
    Hi

    Date is a int

    I have put the following but it didnt like it

    [code]<?
    session_start();
    include ("db.php");
    $y3 = substr($_POST['year'], 0, 3);
    $sql ="SELECT * FROM dates WHERE date >= CAST ('".$y3."0' AS UNSIGNED) AND date <= CAST ('".$y3."9' AS UNSIGNED)";

    $result = @mysql_query($sql,$connection) or die(mysql_error());
    $num = mysql_num_rows($result);

    ?>[/code]

    I get the error

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '('2010' AS UNSIGNED) AND date <= CAST ('2019' AS UNSIGNED)' at line 1

    Any ideas?

    Thanks

    Dave
    [/quote]

    Your other idea worked great. thanks. all fixed

    stay well

    dave
  15. Hello

    thanks for that, it worked great. I have another question about the same form and php page.

    How could we get the sql statement to return all rows which contain the first 3 numbers of whatever has been selected from the drop down list?

    So if 1990 is selected from the drop down on the form, it would return all rows which have 199 in the date column, so 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 as they all start with 199

    Any help would be great

    Thanks

    Dave


    [!--quoteo(post=350035:date=Feb 27 2006, 10:49 PM:name=wickning1)--][div class=\'quotetop\']QUOTE(wickning1 @ Feb 27 2006, 10:49 PM) [snapback]350035[/snapback][/div][div class=\'quotemain\'][!--quotec--]
    The best answer depends on what TYPE you've set date to.

    $y3 = substr($_POST['date'], 0, 3);

    If it's a string type:
    "SELECT * FROM dates WHERE date LIKE '".$y3."%'"

    If it's an int type
    "SELECT * FROM dates WHERE date >= CAST ('".$y3."0' AS UNSIGNED) AND date <= CAST ('".$y3."9' AS UNSIGNED)"

    If it's a date type
    "SELECT * FROM dates WHERE date >= CAST ('".$y3."0' AS DATE) AND date <= CAST ('".$y3."9' AS DATE)"
    [/quote]


    Hi

    Date is a int

    I have put the following but it didnt like it

    [code]<?
    session_start();
    include ("db.php");
    $y3 = substr($_POST['year'], 0, 3);
    $sql ="SELECT * FROM dates WHERE date >= CAST ('".$y3."0' AS UNSIGNED) AND date <= CAST ('".$y3."9' AS UNSIGNED)";

    $result = @mysql_query($sql,$connection) or die(mysql_error());
    $num = mysql_num_rows($result);

    ?>[/code]

    I get the error

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '('2010' AS UNSIGNED) AND date <= CAST ('2019' AS UNSIGNED)' at line 1

    Any ideas?

    Thanks

    Dave
  16. Hi all

    I am wondering if you could help me, basically I have a html form which passes a value to a php page, the value is a date, such as 2001 or 2003, the form looks like

    [code]<form id="sqlfind" method="post" action="sqlfind.php">
    <select name="date">
    <option value="2010">2010</option>
    <option value="2000">2000</option>
    <option value="1990">1990</option>
    </select>
    <input name="Submit" type="submit" value="Search"></form>[/code]

    the sql statement I use on the sqlfind.php page to get the results is

    [code]<?
    session_start();
    include ("db.php");

    $sqlresult = "SELECT * FROM dates WHERE date=".$_POST['date']." AND live=1";

    $dateresult = @mysql_query($sqlresult,$connection) or die(mysql_error());
    $num = mysql_num_rows($dateresult );

    ?>
    [/code]

    At the moment is brings results back for only rows which match the date, so if you select the year 1990 it will only find rows which contain 1990.

    How could I get it to bring back the rows which contain the first 3 numbers of the year, if 1990 is selected it would look for 199 and if 2000 is selected it would look for 200.

    For example, if you select 1990 from the drop down list on the form then the sql will return 1990 and also 1991 1992 1993 1994 1995 and so on. And if I selected 2000 from the drop down list on the form then it would bring back 2001 2002 2003 2004 2005.

    Any help would be great.

    Thanks in advance

    Dave
×
×
  • 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.