DavidAM
Staff Alumni-
Posts
1,984 -
Joined
-
Days Won
10
Everything posted by DavidAM
-
I'm not sure your solution will do what you expect. In FF 3.5.3 it only shows two columns. To make a third column which covers multiple rows, you add it to the first row like this: <table width="586" height="60" border="1" cellpadding="2" cellspacing="2"> <tr> <td width="273" height="20"> </td> <td width="142"> </td> <td width="120" rowspan="3"> </td><!-- ADD THIS CELL --> </tr> <tr> <td height="20"> </td> <td> </td> </tr> <tr> <td height="20"> </td> <td> </td> </tr> </table> the "rowspan" attribute causes the cell to cover the specified number of rows in the table. Then you do NOT include the <TD></TD> for that column in the following cells.
-
maybe something like: $names = array('Bobby', 'Sally', 'Joe', 'Sue', 'Mark', 'Eric', 'Jason', 'Billy', 'Michael', 'Jeremy', 'Jacob'); $maxLen = 140; $list = array(); $line = ''; foreach ($names as $name) { if ((strlen($line) + strlen($name) + 1) > $maxLen) { // +1 for the space $list[] = $line; $line = ''; } $line .= (strlen($line)>0 ? ' ' : '') . $name; } if (strlen($line) > 0) $list[] = $line; // pickup the last line
-
Cookies are stored on the client machine. Sessions use cookies. BUT the only data stored in the session cookie is the ID of the session. The session data is stored on the server. So, PHP receives a session ID and looks up the data using this ID. Yes, a client could modify their session cookie to send a phony session ID, but if that ID does not match a session ID on the server, the server will not find any data for the session. So a session can be "spoofed" but the hacker would need a valid session ID to get anywhere.
-
Actually, since unix timestamps are in seconds, it could be something like: define ('C_ONE_DAY_SECS', 24 * 60 * 60); // Seconds per day $forDate = mktime(0, 0, 0, 9, 25, 2009); $endDate = $forDate + C_ONE_DAY_SECS; $sql = "SELECT * FROM postTable WHERE postDate >= $forDate AND postDate < $endDate"; I use less than ('<') not '<=' on the upper end since the endDate is actually the start of the next day. Note: BETWEEN is inclusive (i.e. >= AND <=) so it will not work in this situation (unless you subtract 1 (one) from $endDate).
-
Rules that Change! Putting In Too Array.
DavidAM replied to paulman888888's topic in PHP Coding Help
Sorry, your post said you wanted to convert that to PHP. So now you say you are extracing the javascript code from a file. So I guess you end up with (in PHP): $lines[0] = "L[0] = new Array('','','','W','','','','','','','','','','','','','','T','');" $lines[1] = "L[1] = new Array('S','E','C','O','N','D','A','R','Y','','R','E','T','R','I','E','V','A','L');" // and so on ... is that right? But I don't understand what you want to do with it now. If you just want to make it into PHP code (like what I gave you) that you can run: foreach ($lines as $ind => $line) { $lines[$ind] = '$' . str_replace(' new', '', $line); } or are you trying to keep it as Javascript and just send it to other files? or do you want to generate that javascript code using PHP? Can you explain - or possibly show - what you want the result to be? -
You will have to re-INSERT the row into the database. The value as truncated when you originally created it.
-
I would not have a seapate table for each team's schedule. But I would build a structure with a couple of tables. I get the impression that the Varsity & JV schedules are the same, so I'll keep those together. Here's how I would setup the database (off the top of my head, this may need work): Table: Teams TeamIDintegerAutoIncrement PrimaryKey Schoolvarchar(50)not null TeamNamevarchar(50)not null Table: Schedule SchedIDintegerAutoIncrement PrimaryKey HomeTeamIDintegerForeign Key to Teams VisitTeamIDintegerForeign Key to Teams GameDatedatetimeNOT NULL VarsityScoreintegerDEAULT NULL JrVarsityScoreintegerDEFAULT NULL You could easily get any team's schedule (with scores) using a (fairly) simple query: SELECT DATE_FORMAT('%a %b %e', s.GameDate) AS GDate, DATE_FORMAT('%r', s.GameDate) AS GTime, h.TeamName AS Home, v.TeamName as Visitors, h.VarsityScore AS HVScore, vVarsityScore AS VVScore, h.JrVarsityScore AS HJScore, vJrVarsityScore AS VJScore FROM Schedule s JOIN Teams h ON s.HomeTeamID = h.TeamID JOIN Teams v ON s.VisitTeamID = v.TeamID WHERE $GetSchedForID IN (s.HomeTeamID, s.VisitTeamID) ORDER BY s.GameDate (I'm not 100% sure about the JOIN statements there, I'm not where I can test it.) But this would let you use a Team's ID from PHP ($GetSchedForID) to get their entire schedule. Scores would be returned and would be empty for future dates. The date and time are combined in one field, and we extract the Day of Week from the date rather than store it separately. For updating the scores, I think I would use a form that presents all games for a selected date (or date range), then enter all of the scores for that date (range) on one page, and have the PHP post script issue updates to the database. The advantage of this design, is you only have to update and query one table for any team, and you only have to update one row for each game.
-
You could add it to the select: $sql=mysql_query("select password, md5('dido') AS testpwd from users where userID='11' "); $result = mysql_fetch_assoc($sql); echo $result['password'] . '=?=' . $result['testpwd']; If they don't matchup, you may want to check the datatype/length of the column in the table; did you use CHAR or VARCHAR?
-
Rules that Change! Putting In Too Array.
DavidAM replied to paulman888888's topic in PHP Coding Help
I'm not at my development computer, but I think you can turn this into a PHP multi-dimensional array by adding a '$' at the beginning and removing the 'new'; then wrap it in php tags ('<?php', '?>); <?php // From L[0] = new Array('','','','W','','','','','','','','','','','','','','T',''); to $L[0] = Array('','','','W','','','','','','','','','','','','','','T',''); $L[1] = Array('S','E','C','O','N','D','A','R','Y','','R','E','T','R','I','E','V','A','L'); $L[2] = Array('','','','R','','','','','','','','','','','','','','P',''); $L[3] = Array('','','','D','A','T','A','','Q','','','','','','E','X','C','E','L'); $L[4] = Array('','','','','C','','','','U','','','','','','','','','R',''); $L[5] = Array('','','','','R','','Q','U','A','N','T','I','T','A','T','I','V','E',''); $L[6] = Array('','','','','O','','','','L','','','','','','','','','C',''); $L[7] = Array('','','','','S','T','A','T','I','S','T','I','C','S','','','','O',''); $L[8] = Array('','','','','S','','','','T','','','','','','','','','R',''); $L[9] = Array('','','','','','','','','A','','','','L','E','G','E','N','D',''); $L[10] = Array('','I','N','F','O','R','M','A','T','I','O','N','','','','','','E',''); $L[11] = Array('','','','','','','','','I','','','','P','R','I','M','A','R','Y'); $L[12] = Array('','','','','','','','','V','','','','','','','','','',''); $L[13] = Array('','','','','','T','I','M','E','L','Y','','','','','','','',''); ?> That will give you a nice PHP array named $L with rows and columns. So $row = 7; $col = 6; echo $L[$row][$col]; // will print: A -
$query="insert into category (name, image, description) values ('".$_POST["name"]."', '".$_POST["image"]."', '".$_POST["description"]."')"; if(!$query)error_message(sql_error()); you're not actually executing the query: $query="insert into category (name, image, description) values ('".$_POST["name"]."', '".$_POST["image"]."', '".$_POST["description"]."')"; // $query is the SQL string $res = mysql_query($query); if (! $res ) error_message(sql_error());
-
You would have to change the link on your page to go to your intercept page, pass in the desired url and do a refresh on a timeout or something; on your main page the link would be something like this: <A href=myIntercept.php?dest=www.google.co.uk>Google Roundabout</A> the myIntercept.php would have to do something along these lines (this is just an outline, you'll have to flesh it out) <?php // Get the user's ultimate destination $dest = $_GET['dest']; // Now show them my page ?> <HTML> <HEAD> <TITLE>INTERCEPTED!!!</TITLE> <!-- Here's where we forward them on to their destination --> <META http-equiv="refresh" content="10;url=http://<?php echo $dest;?>"> </HEAD> <BODY> <H1>INTERCEPTED!!!</H1> <P>I just wanted to see your pretty face before you ran off to <?php echo $dest; ?></P> </BODY> </HTML> In the META refresh tag, the number 10 in the example above is the number of seconds to delay before refreshing the page. The url specifies the page that the refresh will open. You can't use a header('Location ...') call here if you want to display anything to the user because the header redirect will happen before the page gets loaded. If you just want to track the links and not show something, you can use the header after you have done all of your tracking code.
-
OK, all of that HTML at the top of your index page is being sent to the browser. So now it is too late to send any new headers. session_start() needs to send a header, and it can't. If you don't want to just blindly start a session, you could try putting the following at the top of the index (and any other pages that call the logincheck.php) <?php if ( (isset($_GET['m'])) && ($_GET['m'] == 1) ) session_start(); ?> <!DOCTYPE ... Then you only start a session if you are going to need it later. Another way to do this is to put <?php ob_start();?> at the very top of the index. This will hold all the output in a buffer so headers and stuff can be modified. Then, somewhere after doing the logincheck.php (or not doing it) -- say right after the PAGE DETERMINATION block, you will have to call ob_end_flush() to send the headers and whatever has been buffered.
-
If you are using a table, you can force it to a specific (minimum) width, or force each column to a specific (minimum) width and it should not resize with the window. <TABLE style="width: 800px"> <TABLE><TR><TD style="width: 300px">...</TD><TD style="width: 450px"> ... you only have to set the column's width once (I use the first row), the other rows should follow suit.
-
Is this all of the code? I don't see that $s is assigned a value anywhere // Maybe add this line $s = $_GET['s']; // next determine if s has been passed to script, if not use 0 if (empty($s)) { $s=0; } Your old host may have had regsiter_globals turned on, which IMHO is a bad idea.
-
There are a couple of ways to work around this. Post the first few lines of index.php so we can see what is being output and we might be able to suggest a workaround.
-
Stick a loop in there. Something like this ... <div id="header-links"> <?php $queryC = 'SELECT credits FROM user_credits WHERE username = "' . mysql_real_escape_string($_SESSION['username'], $conn) . '"'; $resultC = mysql_query($query, $conn) or die(mysql_error($conn)); foreach ($rowC = mysql_fetch_assoc($resultC)) { echo $rowC['credits'] . '<BR>'; // with appropriate formatting } ?> </div>
-
$GuestbookUser = $_POST["GuestName"] && $_POST["GuestEmail"]; //checking for duplicates {mistake here} && is a logical operator NOT concatenation (? I've never been able to spell that!). Try $GuestbookUser = $_POST["GuestName"] . "," . $_POST["GuestEmail"]; //checking for duplicates {mistake here}
-
Uh, why not just go ahead and put it in the array during the loop? while($row = mysql_fetch_array($result)){ // $days[$row['dateofmonth']] = array('url string', 'text string'); $days[$row['dateofmonth']] = array("'http://www.url.info/" . $classy . "/" . $row['year'] . "/" . $row['monthofyear'] . "/" . $row['dateofmonth'] . "'", 'linked-day'); }
-
Can't fetch a certain data in mysql for some reason.
DavidAM replied to dezkit's topic in PHP Coding Help
while($row = mysql_fetch_array($result)){ $nicks[$row['nickname']][]=$row['server_id']; } $admintype = $row['admintype']; You are retrieving $row['admintype'] after the while loop has completed. When the loop finishes, $row will be false (not a row from the table). As a result there is no 'admintype' element (it's not an array). This is probably throwing an error (add error_reporting(E_ALL); to the beginning of the script). -
SELECT gcap, tcap FROM (...) a LEFT JOIN category ON category.id = type.id You are referring to type.id when there is no table "type" in the query, so no "id" field to check. I'm guessing you want to return the "id" column in the psuedo table (SELECT type.id, type.caption as tcap,genre.caption as gcap FROM type LEFT JOIN genre ON type.id = genre.id UNION SELECT type.id, type.caption as tcap,genre.caption as gcap FROM type RIGHT JOIN genre ON type.id = genre.id WHERE type.id IS NULL ) ( or maybe that second type.id should be genre.id? ) and then JOIN ON "a.id" in the main SELECT.
-
New lines are ignored in HTML. You will have to use nl2br() to convert them to line breaks (<BR>). The htmlspecialchars() should take care of quotes and other special characters. So the command would be echo nl2br(htmlspecialchars($TheString)); Don't switch the two functions around or you'll get the line breaks as clear text. If that does not work. Use the "View Source" command in your browser and take a look at what is being sent. Post that, and some code, and maybe we can help.
-
add an if statement inside the loop ? while ($teams = mysql_fetch_array($result2, MYSQL_ASSOC)) { if ($winid == $teams['teamid']) echo "" . $teams['teamname'].""; } although, I think I would just add AND teamid = $winid to the query rather than return and loop through a bunch of rows that are not used.
-
at the end of the function, you have header("Location: index.php?catId=$catId"); which is loading a new page, so the echo's are not staying on the screen long enough to be seen. You'll either have to echo to a log file and read it later, or comment out the header (for testing) and echo out an HTML link. Then you can read the screen, and then click the link to continue processing to the next page.
-
[SOLVED] Controlling how GROUP BY groups columns
DavidAM replied to flash gordon's topic in MySQL Help
If you are saying that there will be a row with tid of "x" and another row with tid of "0" for the same id, and you don't want the row with tid = 0 unless the row with tid = x does not exist, then I think I would try something like this: SELECT id, tid, asset FROM assets a1 WHERE id IN(1,2,3) AND ( tid = $tid OR (tid = 0 AND NOT EXISTS (SELECT * FROM assets a2 WHERE a2.id = a1.id and a2.tid = $tid))) GROUP BY id Although that looks ugly, so there must be a better way. -
$fileName = 'img 123 comments.ext'; $comments = preg_replace(array('~^img [0-9]+ ~', '~\.ext$~'), '', $fileName) I think that's right; I'm not the best RegEx'r in the world.