Jump to content

socratesone

Members
  • Posts

    33
  • Joined

  • Last visited

    Never

Everything posted by socratesone

  1. My guess is you're using it for some kind of pagination? You could try something like this: <?php $start = $_GET['start']; $rank = ( isset($start) && ( $start > 0 ) ) ? $start : 1; $limit_by = 'LIMIT ' . ($start - 1) . ', ' ($start + 20); $pageNum = 1; // loop through all possible pages for( $iStart = 1; $iStart > $max ; $iStart = $iStart + 20){ $class = ($iStart == $_GET['start'] ) ? 'class="active"' : ''; echo '<a href="results.php?start=' . iStart . '" ' . $class .'>' . $pageNum++ . '</a>'; } ?>
  2. I haven't tried this, but I suggest you do: mysql_query ("UPDATE liga1 SET puncte=($pctsteua + 3), m='1', v='1' WHERE echipa='Steaua' "); note - don't need quotes if puncte is an int, and mathematical expressions should be enclosed in parenthesis.
  3. "arial.ttf" is the file name of a font. In order to put a font in an image, you need to have the font file. A font file is like any other file. It doesn't have to be "arial.ttf". You can download lots of fonts on the internet. When this particular script is run, it is looking for a file named "arial.ttf", but you don't have that file, so it's throwing up all over itself. The script is scared, and doesn't know what to do, but you can help it. You can be the hero and give the script the font it needs. All you have to do is download a font and put it in the same directory as the script, so they can live together in harmony. BE CAREFUL, though! You might download a font that is not named "arial.ttf". In that case, you will need to EDIT the script. That means you have to open it up in your text editor and change "arial.ttf" to something else. However, I don't know what that is. You have to figure that one out on your own, but it shouldn't be too hard, because it will be whatever the name of the font is that you downloaded. For instance, if you download a font called "myAwesomeFont.ttf", you will have to edit the script and change "arial.ttf" to "myAwesomeFont.ttf". Please let me know if you have any questions. I know it can be tricky.
  4. // for simplicity (you can do some cleanup and checking here, too) $start = $_GET['start']; // the rank can be set using basic logic just once $rank = ( isset($start) && ( $start > 0 ) ) ? $start : 1; // This switch statement is really just here to show you what you can do besides a buch of if statements, // but my guess is there is a better way of doing this. // How, exactly, are you using these $active_x1_x2 variables, and why do you need them? switch($start){ case 1: $active_1_20 = 'active'; break; case 21: $active_21_40 = 'active'; break; case 41: $active_41_60 = 'active'; break; case 61: $active_61_80 = 'active'; break; } // the limit can be set using simple math $limit_by = 'LIMIT ' . ($start - 1) . ', ' ($start + 20);
  5. You can use whatever font you want. You just need to make sure the font file exists and the path and file name are correct.
  6. You have some options here. 1) Keep everything you have, but wrap it in a form and create a button, like this: ?> <form action="" method="post"> <?php echo $string; ?> <input type="submit" value="go" /> </form> ...and at the top of the page, add some logic to check the value, and, if present, forward off to the page <?php if(isset($_POST['selection']) && and !empty($_POST['selection'])}{ header("Location: http://www.example.com/" . $_POST['selection']); } ?> ....or.... 2) You can create links instead of a select box // get rid of this // $string='<select name=selection><option value=>modelo</option>'; // change this: // $string .='<option value="'.$row_array[1].'">'.$row_array[0]."</option>"; // to this: $string .= '<a href="'.$row_array[1].'">'.$row_array[0]."</a><br />"; // (you can also change this to any kind of format or wrapper for the <a> tag, such as wrapping them in <li> elements // get rid of this $string .='</SELECT>'; Hope that helps.
  7. Is this code supposed to use the $role variable as the key? '$role' => kry_encrypt_password($password)); If so, you're not going to get what you want. Instead, you're going to get the string litteral '$role' as the key, rather than the variable. If you want to use variables in the key, you must use double quotes rather than single quotes, ie: "members_$role" => kry_encrypt_password($password)); However, I think that you need to re-evaluate what you are doing here. You should probably NOT have multiple users with the same user name. You should probably have a group table that associates user ids with that group. Then, each user will log in with their own user name and their group identity will be in the database.
  8. You're attempting to re-order them in PHP or JavaScript? I'm guessing you're doing the reordering on the client side and storing it via ajax or form submission?
  9. Change this: $result=mysql_query($sql); to this: echo $sql; $result=mysql_query($sql) or die(mysql_error()); And post what you see.
  10. A quick way to do this is just to use a default value. I don't know if this is the behavior you want, though. <INPUT checked="checked" TYPE=RADIO NAME="otherdata" VALUE="Yes">YES<br/> <INPUT TYPE=RADIO NAME="otherdata" VALUE="No">NO<br/>
  11. This isn't the literal connection strings, I hope? mysql_connect("host", "userName", "password"); You are passing in the actual values, right? Not the strings "host", "userName", and "password"?
  12. A couple things: First, you want to alter the form to include the enctype: <form id="whatever" action="whatever" enctype="multipart/form-data" > Then, you want your file field in the form itself: <input type="file" name="image_file" /> Next, you may want to do some javascript validation to make sure it's the right file type. If you have a one-to-one relationship between post and image (one image per post), you will add the field to the database. Finally, you edit your form processing script to include the file upload: // set the path $path = 'path/to/save/filename.jpg'; // handle the upload move_uploaded_file($_FILES['image_file']['tmp_name'], $path) ; // enter into database mysql_query("UPDATE table set `image_path`= '$path'); Note that this is VERY simple, and is NOT meant to be a cut and paste solution. You will probably want to do more to validate server-side, check for existing files to avoid over-writing them, and more. A more in-depth discussion can be found here: http://www.webdeveloper.com/forum/showthread.php?t=101466 Hope that helps.
  13. You could check if the file exists before you call unlink. if(file_exists($picname)){ unlink($picname); }else{echo 'file not found';} if(file_exists("thumbs/".$picname)){ unlink("thumbs/".$picname); }else{echo 'thumb not found';} If you're getting the echo'd error message, make sure that the path is correct, as well.
  14. The easiest way to solve this was to ensure that relationship existed, so I add an addition to the rel table befor I even get here.
  15. I have three tables (not the actual table names): Voters: VoterId | numCandidatesVotedFor Candidates: CandidateId | numVotes VoterCandidateRel FKVoterId | FKCandidateId | numVotes The Voters table has the total number of Candidates that this voter has voted for The Candidates table has the total number of times this Candidate has been voted for The VoterCandidateRel table has the total number of times that a particular voter has voted for a particular Candidate What I would LIKE to be able to do (In MySQL v. 4.0.23) is to update all three tables in one fell swoop with on querie I can do this if the VoterCandidateRel table already has a record of an existing purchase with this query: UPDATE Voters, Candidates, VoterCandidateRel SET Voters.numCandidatesVotedFor=Voters.numCandidatesVotedFor+1, Candidates.numVotes=Candidates.numVotes+1, VoterCandidateRel.numVotes=VoterCandidateRel.numVotes+1 WHERE VoterCandidateRel.FKVoterId = Voters.VoterId AND VoterCandidateRel.FKCandidateId = Candidates.CandidateId AND Voters.VoterId=12345 AND Candidates.CandidateId=12345; However, If the relationship in the VoterCandidateRel doesn't exist, I get 0 rows effected. What I would like to be able to do is to UPDATE the VoterCandidateRel table if the relationship exists, and INSERT a new relationship if it doesn't yet exits, but I would like to be able to do it with a single query, if at all possible. I realize I can use PHP to check if the relationship exists, then do an UPDATE or INSERT after the fact, but that would mean that I would have to make three different queries: 1) To find out if the relationship exists 2) To update the Voters and Candidates Table, and 3) To conditionally insert or update the VoterCandidateRel table. I was wondering if there was any MySQL magic that I can do to do this all in one query, to avoid all the hits to the database.
  16. What do you mean it wont work? What are you seeing in 4.4.4?
  17. I just checked the page. I did a diff of the outputs from both browsers, and, although it detected a difference, I couldn't pinpoint it. So, I took the output of IE and put it into FireFox -- it worked. I took the output of FF and put it into IE -- broken. This doesn't have anything to do with PHP. This is a pure CSS box-model problem with IE. Here's the fix: in default.css: Change this: #page { width: 700px; margin: 0 auto; } to this: #page { width: 720px; margin: 0 auto; } While this fixes the problem that you are seeing, it creates another problem: we increase the width by 20px, which was probably done for a reason. there are a couple other ways to "fix" this, like implementing a box-model hack, or removing the padding on the sidebar: #sidebar { float: left; width: 200px; padding: 0 20px; /* change this to "padding: 0px;" */ background: url(images/img3.gif) no-repeat right top; } More info about the box model problem: http://tantek.com/CSS/Examples/boxmodelhack.html
  18. exit() is used to kill the script. Once its called, your script is dead. You could set a boolean to display the form, like this: $displayForm= true; if($result) { echo 'Client successfully added, to add another <a href="addclient.php">click here</a> or use the navigation links on the right to continue working'; $displayForm=false; } else { // handle your errors } ?> <?php // And wherever you want to put the code: if($displayForm){ ?> <form><fields></form> <?php } ?>
  19. <?php while($row = mysql_fetch_array($result)){ ?> <a href="gallery/<?= $row['Imagename'] ?>" rel="Gallery" title="<?= $row['Caption'] ?>"> <img src="gallery/<?= $row['Thumbname'] ?>" width="<?= $row['Width'] ?>" height="<?= $row['Height'] ?>" alt="<?= $row['Caption'] ?>" border="0"/> </a> <?php } ?>
  20. $query = "SELECT * FROM 1994data, 1995data, 1996data" . " WHERE (" . " 1994data.engfam = '$engfam' OR " . " 1995data.engfam = '$engfam' OR " . " 1996data.engfam = '$engfam'" . ")";
  21. asort() sorts based on value. Since the value is a file returned from readdir(), I'm not sure how its being sorted. You could use usort() and define a callback function that compares the files based on something you determine. Also, you are trying to access the filename as $file, but you are populating the filename into an array. If you do this, you need to access the filename by its array index ei: $file["filename"]; function compareByName($a, $b){ return strcmp($a["filename"], $b["filename"]); } function compareByDate($a, $b){ return ($a["modified"] < $b["modified"]) ? -1 : 1; } $dir = '../wip/VanPictures/Ford/Econoline/thumb/'; $i = 0; if ($handle = opendir($dir)) { while (false !== ($file = readdir($handle))) { $files[$i]['modified'] = filemtime($dir . $file); $files[$i]['filename'] = $file; $i++; } } usort($files, "compareByDate"); foreach($files as $file) { //Do something with the file echo "<img src='" . $dir . $file["filename"] . "'>"; }
  22. How do I use PHP to display page-specific "related pages" links on a webpage? // on the "related.php" included page: // (And this is a quick-and-dirty way of doing it. // The best idea is to use a database of related pages) $currentPage = $_SERVER["PHP_SELF"]; if( strpos($currentPage, 'pageName1') !== false) { $relatedPages = array("link1" => "relatedPage1.htm", "link2" => "relatedPage2.htm"); }elseif(strpos($currentPage, 'pageName2') !== false){ $relatedPages = array("link4" => "relatedPage4.htm", "link3" => "relatedPage3.htm"); }elseif(strpos($currentPage, 'pageName3') !== false){ $relatedPages = array("link1" => "relatedPage1.htm", "link5" => "relatedPage5.htm"); }elseif(strpos($currentPage, 'pageName4') !== false){ $relatedPages = array("link3" => "relatedPage3.htm", "link5" => "relatedPage5.htm"); } Obviously you would want to replace the "pageName1" with the current page, and the "relatedPage1.html" with the related page.
  23. A couple things I just noticed: #1: You'll want to tell the difference between the text field city and the select city, so <select name="citySelect">...etc</select> and <input type="test" name="cityText"> ...would be better
  24. There's no error checking or database handling here, and I haven't tested the code, but it should work: SQL: (State is obviously optional) Create Table Location( LocID INT NOT NULL AUTO_INCREMENT PRIMARY KEY, City VARCHAR(100), State VARCHAR(2) ); PHP for building the options: (note there isn't any error checking here, and I haven't tested this out, so I'm not sure if it works) $result = mysql_query("SELECT City FROM Location WHERE STATE='". $State . "'"); echo "<select name='city'>"; while ($record = mysql_fetch_row($result, MYSQL_ASSOC)) { $city = $record['City']; echo "<option value='$city'>$city</option>"; } echo "</select>\n"; PHP for building adding the new city to the database: $city = $_POST['City']; // or whatever the name of the text field in the HTML is $State = ""; // Not sure how you want to handle this. $result = mysql_query("INSERT INTO Location SET City='". $city . "', State='" . $State ."'");
×
×
  • 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.