Jump to content

Recommended Posts

This is the view of the events (basic)  Can I do the if/else statement to chose font color base of a MySQL Query Result? (see below) And

No matter how I have written this, it will not turn into a scrolling table. I want the headers to stay fixed. I also don't want to rely on Java-most of the staff logs in mobile. I will if I have to though!

 

The other thing I am not seeing how to do, but I know is also possible.... having an "edit event" "view positions" buttons.  I am thinking it has to do with storing a variable, but how do you make sure the variables code pulls the event singularly from your query using the Event_ID ?? 

 

This is my first site outside of an HTML site.  This is the raw synopsis: 

 

Building a site that has users with profiles & 6 permission levels.  Client & various staffing levels; I use php to code the access because it is not so much about being able to query/change the database-its more so I am handling with php.  There is a time log, and keeps up with the pay to the staff and what the client owes per their hours.  This is the first layer view once logged in as any staffmember (sans the edit event which is reserved for high perm staff) upon clicking "view positions" they need to be able to request the shift (separate table-please correct me if I am wrong-I have all foreign keys in database in place so making this event table should be along the same as all the others but with diff variables/queries etc. So in theory all I have to do is get the grabbing of the ID field and using it down)

 

Here is my code. Why is it not setting the client named in green?

 

<html>

<body>

 

<?php require_once('auth.php'); ?>

 

 

<?php $sql = "SELECT * FROM Events ORDER BY EventDate DESC LIMIT 40";

$sqlRes = mysql_query($sql);

$req1 = mysql_num_rows($sqlRes);

$colorpick = $sqlRes['BusinessName'];?>

<div class="event_view">

<table border="1" cellspacing="2" cellpadding="2" width="100%" height="100%" bgcolor="silver" style="border-collapse:collapse;">

<tr>

<th><font face="Arial, Helvetica, sans-serif" color="black">Event Date</font></th>

<th><font face="Arial, Helvetica, sans-serif" color="black">Event Name</font></th>

<th><font face="Arial, Helvetica, sans-serif" color="black">Start Time</font></th>

<th><font face="Arial, Helvetica, sans-serif" color="black">End Time</font></th>

<th><font face="Arial, Helvetica, sans-serif" color="black">Client Name</font></th>

</tr>

 

<?php

$i=0;

while ($i < $req1) {

 

$f1=mysql_result($sqlRes,$i,"EventDate");

$f2=mysql_result($sqlRes,$i,"EventName");

$f3=mysql_result($sqlRes,$i,"Hour");

$f4=mysql_result($sqlRes,$i,"EndHour");

$f5=mysql_result($sqlRes,$i,"BusinessName");

?>

 

<tr>

<td><font face="Arial, Helvetica, sans-serif" color="black"><?php echo $f1; ?></font></td>

<td><font face="Arial, Helvetica, sans-serif" color="black"><?php echo $f2; ?></font></td>

<td><font face="Arial, Helvetica, sans-serif" color="black"><?php echo $f3; ?></font></td>

<td><font face="Arial, Helvetica, sans-serif" color="black"><?php echo $f4; ?></font></td>

<td><?php if($colorpick == 'ClientA') { ?>

<font face="Arial, Helvetica, sans-serif" color="green"><?php echo $f5; ?></font>;

<?php } else($colorpick != 'ClientA'); ?>

<font face="Arial, Helvetica, sans-serif" color="black"><?php echo $f5; ?></font></td>

</tr>

 

<?php

$i++;

}

?>

</table>

</div>

</body>

</html>

This is terrible. If you are developing a complex application/website, do yourself a favor and use a framework from the beginning. That will teach, almost enforce, best practice application design and coding standards.

 

My advice: start again with a framework.

 

Good frameworks: Zend Framework, and Symfony2 is a breeze to work with.

I have looked into "Pre-Fab" Sites etc... There is nothing that does this that I can find that works with tables pre-populated with data.  The last guy they hired took them to the cleaners for 30K over the last three years using someone elses work and it does not work properly.  I am trying to design this custom in order to make sure they keep the last 3/4 years of their business.  I don't know how else to save this info.  This guy has the tables so odd that it is going to require some outside the box thinking in order to keep it.

 

Thanks about the {} getting sleepy last night!

He doesn't mean something like wordpress or drupal, he means an application framework. A framework basically just speeds up the development process by providing you with useful tools and forcing good habits.

 

Here's a few frameworks:

  • Zend
  • CakePHP
  • Lithium (not finished yet)
  • CodeIgniter
  • Symfony
  • Yii
  • Kohana

 

 

Instead of providing you with pre-built pages, a framework provides you with tools needed to create a custom website quickly. Most respectable frameworks are far more secure than anything you would be able to come up with by yourself because they are developed by many people. Unless it's a super high volume website I would follow his suggestion and learn how to use a framework.

I don't believe this is super high content:

 

150 staff

20 managers

2 admin staff

 

350 clients

 

2000 events; 40 current

 

4000 time logs/approved requests for events

 

5000 requests for events

 

Plus the future of the business. I worked for a big company one time and those numbers were at min X1000 so I am going to assume THATS what high data is?

 

I am going to look at the things you mentioned.  I did not go to school for this; I am only good with math and was begged by my friend to help her.  This has almost bankrupted her company-because she believed him when he said that this site is what she needs to have the success and networking abilities etc... and used an addition of 5 wordpress blogs to create the site.  I have those tables from the umpteen number of databases that created (not a multipage blog but 5 separate additions of wordpress!!) Plus a non viewable interaction from the old flash sites databases....  I extracted the data they needed from the tables and at least have it down to 9 tables of data (two are for populating drop down select menus).  I have a very secure login working and bringing you to the login in page per your permission, showing the data, just not displaying the way I want it.  ('auth.php') verifies the session and once it does continues the connection to database through ('dataconnect.php') I also have all of my queries to select/inner join/ or insert into from forms into multiple tables where needed I created and have tested through mysql commands as functioning.  There is a five page public side too, so they will show up in google after I SEO the site-got that one down pat! 

I guess to me it seems like I am almost done which is why I hear "start over with this", and don't like it:)  I am using Expression Web 4, but it is only easy if you are using asp pages except for the color code, however that will look right regardless of the code as long as the punctuation (;)(' ') is right.  I have not read about asp much and the main part of the over all function of this site is to be one column so it looks good on the iphone too.  Thank you for your help-explaining your response is so kind, thank you for doing that-or I never would have understood what he meant by that! 

OK, so I could not get the cakePHP or anything WAMP XAMPP etc... to work! I do however now have a prettier display via a grid:

________________________________________________________________________________________________________

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<title>Example 1 PDatagrid</title>

<link rel="stylesheet" type="text/css" href="style.css" />

</head>

<body>

<?php

require 'pdatagrid.class.php';

 

//Establish a database connection

require 'dbconfig.php';

$conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die('Connection to database failed: ' . mysql_error());

mysql_select_db(DB_NAME) or die ('select_db failed!');

 

//Initialize instance with database connection

$grid = new PDatagrid($conn);

 

//SQL queries to count/select records

$grid->setSqlCount("Select count(*) from AES_Events");

$grid->setSqlSelect("SELECT `EventDate` , `EventName` , `Hour` , `EndHour` FROM AES_Events ORDER BY EventDate DESC");

 

//Base url for navigation links

$grid->baselink = 'example1.php';

 

//Maximum number of page navigation links

$grid->setMaxNavLinks(4);

 

//Rows (records) per page

$grid->setRowsPerPage(5);

 

//Set current page index

if(isset($_GET['page']))

$grid->setPage($_GET['page']);

?>

<table cellspacing="0" cellpadding="0" width="500">

<thead>

<tr>

<td width="20%">Date</td>

<td width="40%">Event Name</td>

<td width="20%">Start</td>

<td width="20%">End</td>

 

</tr>

</thead>

<tfoot>

<tr>

<td colspan="3">

<span id="navlinks"><?php echo $grid->getLinks();?></span>

</td>

</tr>

</tfoot>

<tbody>

<?php echo $grid->getRows();?>

</tbody>

</table>

</body>

</html>

_____________________________________________________________________________________________________________

 

Now what I am not finding, or don't know what to look for is prob more accurate, is how to select that row for further browsing-sending it to the create/edit event form, or view it with the inner join tables etc...  I want to store variable $editevent in a column in the events table, call it during the query, and define it with the code to edit the event, but I really don't know.  If you can even show a code snippit-I can research the pieces to understand and implement it, I just don't know what the functions to create that function are.  Thank you so much!

Okay, first put the code you post within


tags.

 

Second, you're trying to run before you can even crawl.  Stop relying on tutorials and 3rd party code of dubious quality and get yourself a good book.  Throwing a bunch of code at the problem without knowing what your problem actually is, or what the extra code you're slinging around does is the path to heartbreak and ruin. Professional apps, even the small ones, need to be written well, especially if others are going to use them.

 

Third, along those lines, you need to refine your design in a big way.  While PHP's unique feature is the ability to jump in and out of HTML, it's best you do so sparingly.  There's a programming term called Separation of Concerns.  The idea is that each component you use should be concerned with doing one thing well, and not concerned with other tasks.  In an abstract sense, it means keeping your PHP as separate as possible from your HTML and, in turn, your HTML as separate as possible from your JavaScript (which IS NOT the same thing or a subset of Java - they're two completely different languages made by two separate companies).  The idea is also part of the reasoning behind functions, classes,etc. 

 

Furthermore, well written PHP apps do all of their processing first, THEN display the results of that processing. 

 

Finally, you'd also be better of using modern HTML and CSS.  The <font></font> tag is deprecated and no longer in use.

 

Fourth, your original problem was that you never fetched the results from your query.  The mysql_query function only returns a resource.  In order to get the data, you need to invoke a function to fetch it.  I'm partial to mysql_fetch_assoc.

 

Finally, for your current problem, you need to be abundantly clear about what you want, what you have in terms of db data and table structure, and what results you're getting presently.

 

Not my intention to sound harsh.  I'm just trying to get you to put on the brakes before you go too far.  You're missing some fundamentals, and your best solution is to slow down and try to do it the right/smart way.  You'll actually wind up saving time in the long run.

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.