Jump to content

VarHyid

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Everything posted by VarHyid

  1. Thank you very much, this might actually do the job
  2. Hi, Everyone! I have an issue and I'm not even sure if it can be done with PHP, but even this info would help me (to stop looking for an answer). I need to populate a (MySQL) database with stuff which is now written in a (HTML formatted) file. Here are my options: 1. Copy/paste each single field via PHPMyAdmin . 2. Write a little script to extract the necessary parts of text from these files to create a CSV-like content which I would then easily INSERT into the db. Example The files look like this: <!-- SEPARATOR (same throughout the file(s) --> <tr><td> <div style="something"><img src="img/what_i_need_to_extract_1.png"></div> </td><td> <div style="something else"><b>What I need to extract 2</b></div> <div style="something else">What I need to extract 3</div> </td></tr> <!-- SEPARATOR (same throughout the file(s) --> etc ... and it goes like... 100 times in each file in the same standard pattern with the "What I need to extract" parts being completely different each time. Since it's possible to tell when each part required for extraction begins and ends, I would expect the script to look for these key-points (according to the example, it would be: img/ to "></d then "><b> to </b>< and else"> to </div>) and return a result like this (acc. to the example): ('what_i_need_to_extract_1.png', 'What I need to extract 2', 'What I need to extract 3'), (and so on...). Is it possible? Is there a function/option/way to look for a start/end-point like this and fetch the part between these two set points? If so - how? Any help would be appreciated, I'm not expecting a full code, obviously, just a point to the right direction or where to look at would be nice. Thanks in advance.
  3. Oh. Now it actually makes sense. Many thanks. I'll go with if/elseif/eslseif/else.
  4. OK so no more switches to variables to variables to variables to queries to variables... Thanks, will make ifelse's just in case. Still, out of curiosity, any idea why it worked in all 13 out of 15 cases?
  5. Hi, all First off, it's a SOLVED problem which a) still keeps me thinking, but b) requires a question for the future. I'm actually still learning (by doing) PHP so maybe there's a simple reason for this case, in which case - sorry for bothering I'm writing a very simple script that displays 1 of 4 possible events depending on a number in a (MySQL) database. It's really basic. $ttest = $usrfield['ttest']; switch ($ttest) { case ($ttest < 50): $ttestr = "<div>Get at least 50 credits</div>"; break; case ($ttest > 49 && $ttest < 500): $ttestr = "<div><b>RANK 1</b></div><div style='color: #d00000; font-size: 10px;'>You have <b>".$ttest."</b> credits</div>"; break; case ($ttest >= 500 && $ttest < 5000): $ttestr = "<div><b>RANK 2</b></div><div style='color: #d00000; font-size: 10px;'>You have <b>".$ttest."</b> credits</div>"; break; case ($ttest >= 5000): $ttestr = "<div><b>RANK 3</b></div><div style='color: #d00000; font-size: 10px;'>You have <b>".$ttest."</b> credits</div>"; break; } As I said - very basic. There are 15 (almost) EXACT codes, varying by the variable name (for example: $rtest + $rtestr, $ptest + $ptestr and so on) which make a document included in the "main" file which echoes all of them $ptestr, $rtestr, $ttestr etc. The main document also sets $usrfield = mysql_fetch_assoc($resultusr); and $resultusr is a mysql_query selecting a particular user's row with ptest, rtest, ttest... named columns. Here's the funny thing - it works perfectly in 13 out of 15 cases. In 2 cases, where the number is 0 it doesn't display "Get at least 50 credits", but returns "RANK 1..." instead (with 0 within the text). And it's not like these are the only two zeros - there are a 4 more and all 4 work fine and return "Get at least 50 credits". I've been staring at the complete code half an hour, copying/pasting the working part that displays 0 properly and mass-replace "rtest" to "ttest" (for example) and still nothing. I've tried to check/repair the particular MySQL table - PhpMyAdmin says it's OK. All fields have same properties, all are 0-default, decimal(6,0). I've tried to make a separate case for $ttest equaling 0 and one for it being less than 50 and then 0 worked, but... nothing else, still returned 0-case even with 45671. Then I've separated the first case and made an if (case1) else (switch): $ttest = $usrfield['ttest']; if ($ttest < 50) { $ttestr = "<div>Get at least 50 credits</div>"; } else { switch ($ttest) { case ($ttest > 49 && $ttest < 500): $ttestr = "<div><b>RANK 1</b></div><div style='color: #d00000; font-size: 10px;'>You have <b>".$ttest."</b> credits</div>"; break; case ($ttest >= 500 && $ttest < 5000): $ttestr = "<div><b>RANK 2</b></div><div style='color: #d00000; font-size: 10px;'>You have <b>".$ttest."</b> credits</div>"; break; case ($ttest >= 5000): $ttestr = "<div><b>RANK 3</b></div><div style='color: #d00000; font-size: 10px;'>You have <b>".$ttest."</b> credits</div>"; break; } } and surprise, surprise - it works So here's the question - is there something special about the 0 or about switch that it doesn't always work or only with particular numbers ( )? Should I always mix if/else with switch in some particular situations? Or maybe ditch the switch completely and make it an if/elseif for... whatever reason?
×
×
  • 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.