Jump to content

Why wont this work? Grabbing info from text file.


mazman13

Recommended Posts

I am trying to grab info from a text file, and with that information, I will grab info from a table and display it.

 

I do not want to show --SELECT-- so thats why the IF statement is there.

For some reason it will still show --SELECT-- but doesn't read it as such.

If I try to say:

 

$writers == "--SELECT--"

it wont see it. Why does it do it?

 

writers.txt contains:

--SELECT--

Dusty

Laszlo

 

$text = file_get_contents("updates/writers.txt");
$array = explode("\n",$text);
sort($array);
foreach ($array as $writer) {
$writer = strip_tags($writer);
echo"$writer";
	if($writer != "--SELECT--")
	{
	$query = "SELECT COUNT(quality) AS twriter FROM data WHERE writer='$writer' AND date BETWEEN '$year-$month-00' AND 		'$year-$month-32' ";
$result = mysql_query($query)or die(mysql_error());
$row = mysql_fetch_assoc($result);
extract($row);
echo"$writer - $twriter";

	}

}

 

 

Link to comment
Share on other sites

you can use this code

 

$text = file_get_contents("writers.txt");
$array = explode("\n",$text);
sort($array);
foreach ($array as $writer) {
$writer = strip_tags($writer);
echo"$writer";
	if(!preg_match('/^--SELECT--/',$writer))
	{
	$query = "SELECT COUNT(quality) AS twriter FROM data WHERE writer='$writer' AND date BETWEEN '$year-$month-00' AND 		'$year-$month-32' ";
$result = mysql_query($query)or die(mysql_error());
$row = mysql_fetch_assoc($result);
extract($row);
echo"$writer - $twriter";

	}

}

 

still investigating why the pervious code is not working

Link to comment
Share on other sites

If you want to get a better idea of what I am looking for you can go here:

collisionspecialiststx.com/csi

 

We are making a breakdown of customer service approvals for a bodyshop.

 

Its going to look nicer...it's just a rough draft right now.

 

Right now everything works. We can get an overall approval rating for the shop, and a breakdown of the categories and graphs.

 

Now we are trying to take it a few steps further...trying to get an overall approval rating for the service writers, insurance, and techs. You can see where we are getting all of our data from by clicking the "Add Report" link.

Thanks

 

Link to comment
Share on other sites

I'm gonna go ahead and post my entire code for the report, so if you guys know anything to make it easier, you can shoot me your ideas.

<?php 
//Get current date
$month = date("m");
$year = date("Y");

//Selected date program
$sel = $_REQUEST["action"];
if($sel == "view_date")
	{
	$month = $_REQUEST['s_month'];
	$year = $_REQUEST['s_year'];
	}
?>
<strong><font color="#333333" size="3" face="Arial, Helvetica, sans-serif">Report for <?php echo"$month-$year";?></font></strong>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>?action=view_date" method="post">
  <p>
    <select name="s_month" id="s_month">
      <option value="01" <?php if ($month == "01") {echo"selected=\"selected\"";}?>>January</option>
      <option value="02" <?php if ($month == "02") {echo"selected=\"selected\"";}?>>February</option>
      <option value="03" <?php if ($month == "03") {echo"selected=\"selected\"";}?>>March</option>
      <option value="04" <?php if ($month == "04") {echo"selected=\"selected\"";}?>>April</option>
      <option value="05" <?php if ($month == "05") {echo"selected=\"selected\"";}?>>May</option>
      <option value="06" <?php if ($month == "06") {echo"selected=\"selected\"";}?>>June</option>
      <option value="07" <?php if ($month == "07") {echo"selected=\"selected\"";}?>>July</option>
      <option value="08" <?php if ($month == "08") {echo"selected=\"selected\"";}?>>August</option>
      <option value="09" <?php if ($month == "09") {echo"selected=\"selected\"";}?>>September</option>
      <option value="10" <?php if ($month == "10") {echo"selected=\"selected\"";}?>>October</option>
      <option value="11" <?php if ($month == "11") {echo"selected=\"selected\"";}?>>November</option>
      <option value="12" <?php if ($month == "12") {echo"selected=\"selected\"";}?>>December</option>
    </select>
    <input name="s_year" type="text" id="s_year" size="4" maxlength="4" />
    <input type="submit" name="Submit" value="Submit" />
  </p>
</form>
<strong><font size="3" face="Arial, Helvetica, sans-serif">Shop Approval Rating<br />
</font></strong>
<?php
$user="user";
$host="localhost";
$password="";
$database="database";
$connection = mysql_connect($host,$user,$password)
	or die ("Sorry. Something messed up and it couldn't connect to the dumb server.");
$db = mysql_select_db($database, $connection)
	or die ("Something is messed up with the database.");

//Collect main total
$query = "SELECT * FROM data WHERE date BETWEEN '$year-$month-00' AND '$year-$month-32'";
$result = mysql_query($query)
	or die ("Can't do anything with the query!");
$total = mysql_num_rows($result);
$maintotal = ($total * ;

//Overall GREETED rating
$query = "SELECT COUNT(greeted) AS y_greet FROM data WHERE greeted='Y' AND date BETWEEN '$year-$month-00' AND '$year-$month-32'";
$result = mysql_query($query)or die(mysql_error());
$row = mysql_fetch_assoc($result);
extract($row);
$total_greet = number_format(($y_greet * 100 / $total),1)."%";

//Overall QUALITY rating
$query = "SELECT COUNT(quality) AS y_qual FROM data WHERE quality='Y' AND date BETWEEN '$year-$month-00' AND '$year-$month-32'";
$result = mysql_query($query)or die(mysql_error());
$row = mysql_fetch_assoc($result);
extract($row);
$total_qual = number_format(($y_qual * 100 / $total),1)."%";

//Overall CLEANLINESS rating
$query = "SELECT COUNT(cleanliness) AS y_clean FROM data WHERE cleanliness='Y' AND date BETWEEN '$year-$month-00' AND '$year-$month-32'";
$result = mysql_query($query)or die(mysql_error());
$row = mysql_fetch_assoc($result);
extract($row);
$total_clean = number_format(($y_clean * 100 / $total),1)."%";

//Overall SERVICE rating
$query = "SELECT COUNT(service) AS y_serv FROM data WHERE service='Y' AND date BETWEEN '$year-$month-00' AND '$year-$month-32'";
$result = mysql_query($query)or die(mysql_error());
$row = mysql_fetch_assoc($result);
extract($row);
$total_serv = number_format(($y_serv * 100 / $total),1)."%";

//Overall INFORMED rating
$query = "SELECT COUNT(informed) AS y_info FROM data WHERE informed='Y' AND date BETWEEN '$year-$month-00' AND '$year-$month-32'";
$result = mysql_query($query)or die(mysql_error());
$row = mysql_fetch_assoc($result);
extract($row);
$total_info = number_format(($y_info * 100 / $total),1)."%";

//Overall PROMISED rating
$query = "SELECT COUNT(promised) AS y_prom FROM data WHERE promised='Y' AND date BETWEEN '$year-$month-00' AND '$year-$month-32'";
$result = mysql_query($query)or die(mysql_error());
$row = mysql_fetch_assoc($result);
extract($row);
$total_prom = number_format(($y_prom * 100 / $total),1)."%";

//Overall ADDITIONAL rating
$query = "SELECT COUNT(additional) AS y_add FROM data WHERE additional='Y' AND date BETWEEN '$year-$month-00' AND '$year-$month-32'";
$result = mysql_query($query)or die(mysql_error());
$row = mysql_fetch_assoc($result);
extract($row);
$total_add = number_format(($y_add * 100 / $total),1)."%";

//Overall REFER rating
$query = "SELECT COUNT(refer) AS y_refer FROM data WHERE refer='Y' AND date BETWEEN '$year-$month-00' AND '$year-$month-32'";
$result = mysql_query($query)or die(mysql_error());
$row = mysql_fetch_assoc($result);
extract($row);
$total_refer = number_format(($y_refer * 100 / $total),1)."%";

//TOTAL Overall Shop approval
$stotal = $y_add + $y_qual + $y_clean + $y_serv + $y_info + $y_prom + $y_add + $y_refer;
$shoptotal = number_format(($stotal * 100 / $maintotal),1)."%";
echo "<strong><font size=\"5\" face=\"Arial, Helvetica, sans-serif\">$shoptotal</font></strong>";
?><br /><br />
<br />
<font face="Arial, Helvetica, sans-serif"><strong>Shop Approval Breakdown<br />
</strong></font>
<table width="100%" border="0" cellspacing="4" cellpadding="4">
  <tr>
    <td width="87%" valign="middle"><table width="75%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="12%" valign="bottom"><strong><font size="1" face="Arial, Helvetica, sans-serif"><?php echo"$total_greet"; ?></font></strong><Br />
	<img src="images/greeting.gif"><br />
	<?php
		$i = 1;
while ($i <= $total_greet) {
echo"<img src=\"images/greeting.gif\"><br>";   
$i++;}?>		</td>
        <td width="11%" valign="bottom">
	<strong><font size="1" face="Arial, Helvetica, sans-serif"><?php echo"$total_qual"; ?></font></strong><Br /><img src="images/quality.gif"><br />
	<?php
		$i = 1;
while ($i <= $total_qual) {
echo"<img src=\"images/quality.gif\"><br>";   
$i++;}?></td>
        <td width="11%" valign="bottom">
	<strong><font size="1" face="Arial, Helvetica, sans-serif"><?php echo"$total_clean"; ?></font></strong><Br /><img src="images/clean.gif"><br /><?php
		$i = 1;
while ($i <= $total_clean) {
echo"<img src=\"images/clean.gif\"><br>";   
$i++;}?></td>
        <td width="10%" valign="bottom"><strong><font size="1" face="Arial, Helvetica, sans-serif"><?php echo"$total_serv"; ?></font></strong><Br /><img src="images/service.gif"><br />
          <?php
		$i = 1;
while ($i <= $total_serv) {
echo"<img src=\"images/service.gif\"><br>";   
$i++;}?></td>
        <td width="12%" valign="bottom"><strong><font size="1" face="Arial, Helvetica, sans-serif"><?php echo"$total_info"; ?></font></strong><Br /><img src="images/info.gif"><br />
          <?php
		$i = 1;
while ($i <= $total_info) {
echo"<img src=\"images/info.gif\"><br>";   
$i++;}?></td>
        <td width="11%" valign="bottom"><strong><font size="1" face="Arial, Helvetica, sans-serif"><?php echo"$total_prom"; ?></font></strong><Br /><img src="images/promised.gif"><br />
          <?php
		$i = 1;
while ($i <= $total_prom) {
echo"<img src=\"images/promised.gif\"><br>";   
$i++;}?></td>
        <td width="10%" valign="bottom"><strong><font size="1" face="Arial, Helvetica, sans-serif"><?php echo"$total_add"; ?></font></strong><Br /><img src="images/additional.gif"><br />
          <?php
		$i = 1;
while ($i <= $total_add) {
echo"<img src=\"images/additional.gif\"><br>";   
$i++;}?></td>
        <td width="16%" valign="bottom"><strong><font size="1" face="Arial, Helvetica, sans-serif"><?php echo"$total_refer"; ?></font></strong><Br /><img src="images/refer.gif"><br />
          <?php
		$i = 1;
while ($i <= $total_refer) {
echo"<img src=\"images/refer.gif\"><br>";   
$i++;}?></td>
        <td width="7%"> </td>
      </tr>
      <tr>
        <td valign="bottom"><strong><font size="1" face="Arial, Helvetica, sans-serif">SATISFIED</font></strong></td>
        <td valign="bottom"><strong><font size="1" face="Arial, Helvetica, sans-serif">QUALITY</font></strong></td>
        <td valign="bottom"><strong><font size="1" face="Arial, Helvetica, sans-serif">CLEAN</font></strong></td>
        <td valign="bottom"><strong><font size="1" face="Arial, Helvetica, sans-serif">SERVICE</font></strong></td>
        <td valign="bottom"><strong><font size="1" face="Arial, Helvetica, sans-serif">INFORMED</font></strong></td>
        <td valign="bottom"><strong><font size="1" face="Arial, Helvetica, sans-serif">PROMISED</font></strong></td>
        <td valign="bottom"><strong><font size="1" face="Arial, Helvetica, sans-serif">RETURNS</font></strong></td>
        <td valign="bottom"><strong><font size="1" face="Arial, Helvetica, sans-serif">REFER</font></strong></td>
           </tr>
    </table></td>
  </tr>
</table>
<?php 
//Service writer stats

$array = file("updates/writers.txt");
sort($array);
foreach ($array as $writer) {
$writer = strip_tags($writer);
	if($writer != "--SELECT--")
	{
	$query = "SELECT COUNT(quality) AS twriter FROM data WHERE writer='$writer' AND date BETWEEN '$year-$month-00' AND 		'$year-$month-32' ";
$result = mysql_query($query)or die(mysql_error());
$row = mysql_fetch_assoc($result);
extract($row);
echo"$writer - $twriter";

	}

}



?>

 

 

And here is the mock data I have in my database to make this happen...I didn't have anytime to clean it up. But maybe you can get some ideas out of it.:

 

ID 	fname 	lname 	phone 	ro 	writer 	tech 	comment 	date 	time 	greeted 	quality 	cleanliness 	service 	informed 	promised 	additional 	refer 	insurance 	recommend 	source 	paysource
Edit 	Delete 	35 	  	  	-- 	  	Dusty 	--SELECT--
  	2007-10-29 00:00:00 	8 	Y 	Y 	Y 	Y 	Y 	Y 	N 	Y 	  	  	--SELECT--
--SELECT--
Edit 	Delete 	34 	  	  	-- 	dsad 	Dusty 	--SELECT--
  	2007-10-29 00:00:00 	8 	Y 	Y 	Y 	Y 	Y 	Y 	N 	Y 	X 	X 	--SELECT--
--SELECT--
Edit 	Delete 	33 	  	  	-- 	  	Laszlo 	--SELECT--
  	2007-10-29 00:00:00 	7 	Y 	Y 	Y 	Y 	Y 	Y 	N 	Y 	N 	N 	--SELECT--
--SELECT--
Edit 	Delete 	32 	gfdgfdgfd 	  	-- 	gdfgdf 	Dusty
--SELECT--
  	2007-10-29 00:00:00 	7 	Y 	Y 	Y 	Y 	N 	Y 	Y 	Y 	Y 	Y 	--SELECT--
--SELECT--
Edit 	Delete 	31 	  	  	-- 	  	Laszlo 	--SELECT--
  	2007-10-29 00:00:00 	6 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	--SELECT--
--SELECT--
Edit 	Delete 	30 	  	  	-- 	  	Dusty 	--SELECT-- 	  	2007-10-29 06:47:00 	18 	Y 	Y 	Y 	N 	Y 	Y 	Y 	Y 	  	  	--SELECT-- 	--SELECT--
Edit 	Delete 	29 	  	  	-- 	  	Dusty
--SELECT--
  	2007-10-26 00:00:00 	18 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	  	  	--SELECT--
--SELECT--
Edit 	Delete 	28 	  	  	-- 	  	Dusty
--SELECT--
  	2007-10-26 00:00:00 	18 	Y 	Y 	Y 	Y 	Y 	Y 	N 	Y 	  	  	--SELECT--
--SELECT--
Edit 	Delete 	27 	  	  	-- 	  	Dusty
--SELECT--
  	2007-10-26 00:00:00 	18 	Y 	Y 	Y 	Y 	Y 	Y 	N 	Y 	  	  	--SELECT--
--SELECT--
Edit 	Delete 	25 	  	  	-- 	  	Dusty
--SELECT--
  	2007-10-26 00:00:00 	18 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	  	  	--SELECT--
--SELECT--
Edit 	Delete 	26 	  	  	-- 	  	Dusty
--SELECT--
  	2007-10-26 00:00:00 	18 	Y 	Y 	Y 	Y 	Y 	Y 	N 	Y 	  	  	--SELECT--
--SELECT--
Edit 	Delete 	36 	  	  	-- 	  	Laszlo
--SELECT--
  	2007-10-29 00:00:00 	8 	Y 	Y 	Y 	  	  	  	  	  	  	  	--SELECT--
--SELECT--

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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