Jump to content

Pikachu2000

Staff Alumni
  • Posts

    11,377
  • Joined

  • Last visited

  • Days Won

    11

Posts posted by Pikachu2000

  1. It seems so. I wrote a quick workaround for it, maybe you could incorporate it into a function and use it.

    $occurrence = 'first';
    $day_name = 'thursday';
    $month = 'April';
    $year = 2010;
    $date = (int) date("d", strtotime($occurrence . " " . $day_name . " " . $month . " " . $year));
    if( $occurrence == 'first' && $date >= 8 ) {
         $date -= 7;
    }
    echo $date;
    

  2. Of course, what PFMaBiSmAd just posted is also possible. Additionally, if you execute an identical UPDATE query multiple times, it will return "0 row(s) affected", because no fields were changed after the first UPDATE, even though the subsequent queries succeeded.

  3. What error are you getting?

    $result = mysql_query($query) or die(mysql_error());

    Also note that form data should NEVER be allowed in a DB query without being properly sanitized with typecasting, trim()ing, mysql_real_escape_string() etc.

  4. at the top of all scripts using $_SESSION data: session_start();

     

    $_SESSION['id'] = mysql_real_escape_string(trim($_GET['id'])); (if id is a string)

    -OR-

    $_SESSION['id'] = (int) trim($_GET['id']); (if id is an integer)

     

    Regarding session_register(): "This function has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged."

  5. I don't see where you are assigning the $_GET['id'] value to the $id variable. If this method worked on other installations, it probably relied on REGISTER_GLOBALS = On.

    Also, change your tags from the short open <? tags to the standard <?php open tags, and remove the single quotes from WHERE id = '$id' as integers should not be quoted in DB queries.

    $id = (int) trim($_GET['id']) // assuming id should always be an integer, trim spaces and typecast it as (int) for the DB query
    

  6. If I'm reading the question right, you want to be able to edit what is returned from the DB and update those same DB fields with the data entered in the form fields, correct?

    If so, to populate the text areas use

     

    echo '<input type="hidden" name="record_id" value="' . $row['record_id'] . '" />'
    echo '<textarea name="question" rows="3" cols="40">' . $row['question'] . '</textarea>';
    

     

    Then when the form is submitted (check for submission with an isset() ), sanitize the input and run the UPDATE query, setting the fields to the new values WHERE the db_record_id = submitted_record_id.

  7. I just figured out what is going on here. If you typecast the $xx variable as an integer when you assign its value from $linknum, it works just fine. I also made the code a little more compact by eliminating redundancy in assigning values to variables.

    <?php
    $xx = (int) $_GET['linknum']; // typecast as an integer here, now the != comparison works when value is passed via URL.
    $data = file ("Source_file.txt");
    $b = fopen("New_File.txt", "w+");
    foreach ($data as $zz) {
    if ($zz != $xx){
    	fwrite($b, $zz);
    }
    }
    ?>
    

  8. Try checking what happens in the conditional . . .

    if(strpos($line,"<indexTitle>")) { //Look for indexTitle tag
    	echo 'Found tag in $line';
    	$indexTitle = $line; //Set indexTitle as the current line
    	$indexTitle = str_replace("<indexTitle>", "", $indexTitle); //Strip both indexTitle tags
    	$indexTitle = str_replace("</indexTitle>", "", $indexTitle);
    } else {
    	echo 'Did NOT find tag in $line';
    }
    }
    

  9. You just need to figure out where to start the numbering with a simple query to set the initial value of $i .

    $query = "SELECT index FROM tbl_name WHERE some_field = 'some_value'";
    $result = mysqli_query($dbc, $query);
    $i = mysqli_num_rows($result);
    while( $array = mysqli_fetch_assoc($result) ) {
         echo $i . " - " . $array['index'];
         $i --;
    }
    

  10. Set a variable to integer 1, then echo and increment it in the while statement.

    $i = 1;
    while( $array = mysqli_fetch_assoc($result) {
         echo $i . " - " . $array['index'];
         $i ++;
    }
    

  11. If there are only 8 records, you can't expect it to retrieve and display 10 of them. But are you saying the loop displays the same record 8 times instead of displaying all 8 of them? The query looks off to me. You are assigning the value to $post_tilte outside of the while{} loop, therefore it never changes. Try this, but note that I didn't correct the spelling of title, so you'll need to edit that if you corrected it locally.

    <?php
    
       include 'connect.inc';
       echo "recent posts";
       $query = "SELECT tilte FROM comments ORDER BY date DESC LIMIT 10"; // separate the query, and you should only select necessary fields rather than wildcard * all
       $result = mysql_query($query); //execute the query
       while($array = mysql_fetch_assoc($result)) {
       echo $array['tilte'];
    }
    ?>
    

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