homepage Welcome to WebmasterWorld Guest from 54.196.168.78
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderators: physics

Databases Forum

    
Newbie Sucessfully Connected to mySQL - need some help
frankb3




msg:4314738
 3:58 pm on May 19, 2011 (gmt 0)

I have successfully connected mySQL db to my web site with a Filemaker front end. Lots of trial and error, but it's working.

I need some formatting help if possible.

-Combining the content of three data fields into one field in my resulting table.

-Have the first two fields reside on the first line, and the third field starting on the second line

-Stylize the text and color on the first two fields
-Stylize the table to be dotted apposed to solid.
(any on another note) how to accept photos into mySQL. That's not working.

Here's my code so far:

<?php
$con = mysql_connect (info));
}

mysql_select_db("my database", $con);

$result = mysql_query("SELECT * FROM my_table WHERE Class_Year='2001' AND Deceased='No' ORDER BY Last_Name ASC ");

echo "<table border='1'> <table style='dotted'> (dotted command isn't working)

<tr>
<th>Name</th>
<th>Bio</th>
</tr>";

while($row = mysql_fetch_array($result))
{
echo "<tr>";

echo "<td>" . $row['Directory_Listing_Name_Year'] . "</td>";
echo "<td>" . $row['Directory_Listing_03'] . "</td>";
echo "</tr>";
}
echo "</table>";

mysql_close($con);
?>

 

rocknbil




msg:4314806
 5:20 pm on May 19, 2011 (gmt 0)

-Combining the content of three data fields into one field in my resulting table.


Don't get this one, you appear to be outputting the two fields as individual table cells, isn't that what you want? Just put them both in one cell (?)

echo "<td>" . $row['Directory_Listing_Name_Year'] . ' ' . $row['Directory_Listing_03'] . "</td>";

-Have the first two fields reside on the first line, and the third field starting on the second line


I don't see a third, but it would be something like this (with one echo)


while($row = mysql_fetch_array($result)) {
echo "
<tr><td>" . $row['Directory_Listing_Name_Year'] . '</td><td>' . $row['Directory_Listing_03'] . "</td></tr>
<tr><td colspan=\"2\">" . $row['the-third-field'] . "</td></tr>
";
}


Note two rows (tr's) and that your columns muse add up: the second two must have a colspan of two to match the first.

-Stylize the text and color on the first two fields
-Stylize the table to be dotted apposed to solid.


Both of these are CSS questions. There is no dotted "command." This is further complicated by the fact that a border on a table only applies to the outside of the table when styled with CSS (It's not the same as the border attribute.) If you want borders in the cells you must style them so. But something that will get you started, add this to your CSS file.

#my-table { border: 1px dotted #808080; }
.first-row { background:#ebebeb; color: #000080; } /* dark blue on a light gray */
.second-row { background: #000; color: #fff; } /( white on black BG */

Include this somewhere between the <head> and </head> of your page output (template? Hard coded?) where "style.css" contains the previous.

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

Then add the styles to your PHP


echo "<table id=\"my-table\">";
while($row = mysql_fetch_array($result)) {
echo "
<tr><td class=\"first-row\">" . $row['Directory_Listing_Name_Year'] . '</td><td>' . $row['Directory_Listing_03'] . "</td></tr>
<tr><td colspan=\"2\" class=\"second-row\">" . $row['the-third-field'] . "</td></tr>
";
}
echo "</table>";


(any on another note) how to accept photos into mySQL. That's not working.


You can store them as blobs directly in the DB, but a more traditional method, and less taxing on your database, is to upload them as plain old files somewhere and store only the file name in the database. You'd store it like any other string, and output it like ordinary HTML . . .

echo "<img src=\"/path/to/" . $row['filename'] . "\" alt=\"" . $row['pagetitle'] . "\">";

frankb3




msg:4314886
 7:18 pm on May 19, 2011 (gmt 0)

Some great help here! Seems to make sense, and is working.

On the photos...I'm storing them through Wufoo, and I have link addresses sent to me. Will that work?

frankb3




msg:4314901
 8:00 pm on May 19, 2011 (gmt 0)

what do you mean on the
"\" alt=\"" . $row['pagetitle'] . "\">";
frankb3
New User
View member profile
edit post
send member a local msg
[print msg]
report msg
joined:May 15, 2011
posts: 7
#:4314886new post indicator

rocknbil




msg:4315441
 5:57 pm on May 20, 2011 (gmt 0)

I have link addresses sent to me. Will that work?


You mean image URL's? Yeah that should work.

The alt attribute of images is important and required. One of the problems with programming (or any other isolated skillset that ignores other technologies involved) is a lot of programming is being generated without semantic meaning or to HTML spec; if it works and I like what I see, good enough. Who cares if it validates or not. :-)

The example I posted uses the page title for an alt value in the image. You may find another field in your database is better for this purpose (person's name?)

frankb3




msg:4316540
 9:39 pm on May 23, 2011 (gmt 0)

I've switched the image source to Smug Mug as Wufoo has secure only access to the files. Smug mug is working ok. I'm having an issue now with images with no link showing up as blue boxes with ? marks in them in Internet Explorer and Safari. Firefox seems to work ok. Spanning code also doesn't work the same in all three browsers....

Here;s my table code as it stands now:

</tr>";


while($row = mysql_fetch_array($result)) {
echo "
<tr><td><b>" . $row['Directory_Listing_Name_Year'] . '</b> </td><td span class="style42">' . $row['Support_Denote'] . "</td><tr>
<td colspan=\"2\">" . $row['Directory_Listing_03'] . "</td>
<td colspan=\"4\"<tr><td><img src=\"". $row['Attach_your_class_photo']."\">
<td><td span> <img src=\"". $row['Attach_a_recent_photo']."\"> </td></tr>
";
}
echo "</table>";

Any problems you can help me spot?

Thanks

Frank

rocknbil




msg:4316971
 4:47 pm on May 24, 2011 (gmt 0)

what does the output look like for this line? (I mean, view page source on output . . .)

<td colspan=\"4\"<tr><td><img src=\"". $row['Attach_your_class_photo']."\"></td> <!-- probably not it, but missing a closing td here -->

You have a funny rowset there - the second two are spanning 2 and 4 columns which adds up to 6 but the first row has no col/row spans. Also there is no attribute "span" for td, a span is an inline element of it's own:

<tr><td colspan="?"><b>" . $row['Directory_Listing_Name_Year'] . '</b> </td><td colspan="?" span? class="style42">' . $row['Support_Denote'] . "</td><tr>
<td colspan=\"2\">" . $row['Directory_Listing_03'] . "</td>
<td colspan=\"4\"<tr><td><img src=\"". $row['Attach_your_class_photo']."\"></td>
<td><td span?> <img src=\"". $row['Attach_a_recent_photo']."\"> </td></tr>

frankb3




msg:4317133
 10:25 pm on May 24, 2011 (gmt 0)

Are there variables that should go where the ?'s are?
As is, I got an error.

rocknbil




msg:4317505
 4:45 pm on May 25, 2011 (gmt 0)

Well, I don't know . . . I'm saying the math doesn't add up on your table colspans. Go back to basic HTML and table layout. Tables have rowspans and colspans. Say you have a table

cell|cell|cell|cell
two |cell---------|
rows|cell-----|cell|

So the first row is 4 cells, the second spans two rows and has one cell spanning three columns, and the last row has one cell spanning two columns. That would be something like this.


<table>
<tr>
<td>cell</td>
<td>cell</td>
<td>cell</td>
<td>cell</td>
</tr>
<tr>
<td rowspan="2">two rows</td>
<td colspan="3">cell</td>
</tr>
<tr>
<td colspan="2">cell</td>
<td>cell</td>
</tr>
</table>


The third row can only span a total of three columns because the first cell in row 2 has a rowspan of two. I'm suspecting your abberant layout **might** have something to do with the broken table.

When you start to get fuzzled on tables, add a border to them and you can see what's up:

<table border="1">

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved