Jump to content

Recommended Posts

I have almost made all the script to place into database I have the following;

 

CREATE TABLE `news` (

  `id` bigint(20) NOT NULL auto_increment,

  `title` text NOT NULL,

  `date` text NOT NULL,

  `content` longtext NOT NULL,

  PRIMARY KEY  (`id`)

) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=25 ;

 

But I need to have also photo option in database, what is the data type name for images or folders?;

 

The database im trying to create will display images and title with description text and date similar to this site (worldpress.org)

 

Thanks in advance

 

 

Link to comment
https://forums.phpfreaks.com/topic/49291-database-table-help/
Share on other sites

My recommendation would be not to store the images within the database directly, but rather to store a reference to the image and store the image within an images directory on your server.

 

If you do indeed choose to store images directly in the DB after all, you need to check out the BLOB (Binary Large Object) data type.

Link to comment
https://forums.phpfreaks.com/topic/49291-database-table-help/#findComment-241518
Share on other sites

Oh, thats a very good thought, so to store the images in a folder like you suggest, how differently than will i need to set up the databse to read from that?

 

CREATE TABLE `news` (

  `id` bigint(20) NOT NULL auto_increment,

  `title` text NOT NULL,

  `date` text NOT NULL,

  `content` longtext NOT NULL,

  `blob` ?????

  PRIMARY KEY  (`id`)

) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=25 ;

Link to comment
https://forums.phpfreaks.com/topic/49291-database-table-help/#findComment-241541
Share on other sites

If you are uploading the images to a folder, all you would need to do is store the image name in a varchar field and then reference the images folder when you print out your news item. So, your table would simply need an images column with a varchar:

CREATE TABLE news (
  id integer unsigned auto_increment primary key,
  title varchar(200) not null,
  `date` DATE not null,
  content longtext not null,
  image varchar(40) default null
)

 

Also, I've made some recommendations for other data types that may fit your columns slightly better. Hope this helps.

Link to comment
https://forums.phpfreaks.com/topic/49291-database-table-help/#findComment-241574
Share on other sites

Also will ( image varchar(40) default null ) be enough to have it outputed onto my webpage as 1 big image  as the main pic and when they click in it will display however many more pics on the next page? or will I have to set that in php?

 

varchar(40) simply lets you store a string up to 40 characters long. What you do with it is entirely up to you. For instance, you most likely should only store the filename ('mypic.jpg', 'songster.mp3', etc) in that field. Then, when you query, you can simply use that name to display the image where you'd like:

<?php
$q = mysql_query("SELECT * FROM news ORDER BY `date` DESC");
if (mysql_num_rows($q) > 0) {
  while ($rec = mysql_fetch_assoc($q)) {
    echo "<div class=\"news_entry\">\n";
    echo "<h1>$rec[title]</h1>\n";
    echo !empty($rec['image']) ? "<img src=\"images/$rec[image]\" />\n" : '';
    echo "<p>" . nl2br($rec['content']) . "</p>\n";
    echo "<p>Posted " . date('F j, Y', strtotime($rec['date'])) . "</p>\n";
    echo "</div>\n";
  }
}
?>

 

Hope that helps some.

Link to comment
https://forums.phpfreaks.com/topic/49291-database-table-help/#findComment-242239
Share on other sites

Actually I have the code working perfectly now (bottom of webpage "ball room" event except for one thing;

seo2webdesign.com/clients/nzsocietythailand.php

 

I want the "title"  and "image" to be a link so when they click on that it will also take them to a secondary page, do i need to edit code here to suit?

 

<?php

$q = mysql_query("SELECT * FROM news ORDER BY `date` DESC");

if (mysql_num_rows($q) > 0) {

  while ($rec = mysql_fetch_assoc($q)) {

    echo "<div class=\"news_entry\">\n";

    echo "<h1>$rec[title]</h1>\n";

    echo !empty($rec['image']) ? "<img src=\"images/$rec[image]\" />\n" : '';

    echo "<p>" . nl2br($rec['content']) . "</p>\n";

    echo "<p>Posted " . date('F j, Y', strtotime($rec['date'])) . "</p>\n";

    echo "</div>\n";

  }

}

?>

 

 

and do I need to make a secondary page and add code for it to follow from?

Link to comment
https://forums.phpfreaks.com/topic/49291-database-table-help/#findComment-243209
Share on other sites

I have the script working here now : nzsocietythai.org/nzsocietythailand.php

 

but i want to have it so when i click on the image it will go to page with info? what code do i need to set in different page and have link on it?

 

should i also add this code somewhere on the query? <a href="<?php echo 'title-' . $link .'-'. strtolower($row['reference']) .'.php'; ?>">

Link to comment
https://forums.phpfreaks.com/topic/49291-database-table-help/#findComment-244172
Share on other sites

say up to 3 images,

and the long description thats it. Nice and simple.....

 

the first page is just 1 image they click from this page "nzsocietythai.org/nzsocietythailand.php" than when it takes them to the secondary page it will show the same image but much bigger, with 2 more images beside it and longer description....

Link to comment
https://forums.phpfreaks.com/topic/49291-database-table-help/#findComment-244237
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.